0
点赞
收藏
分享

微信扫一扫

Robot 添加chrome go_forward关键字,浏览器前进功能

有时候需要使用robot处理浏览器前进、后退等功能时,发现selnium2Library库缺少关键字,只有浏览器后退关键字Go Backe,前进关键字没有,其实在selnium中有这个关键字,只是没有开放出来,如图

Robot 添加chrome go_forward关键字,浏览器前进功能_封装

 

由上面可以分析得出,此关键字只是没有添加到selnium2library库中,其实已经封装好底层的处理方法,则添加此功能需要修改2个文件:

_browsermanagement.py(C:\Python27\Lib\site-packages\Selenium2Library\keywords)添加下面红色代码至go_back方法下面

def go_back(self):
"""Simulates the user clicking the "back" button on their browser."""
self._current_browser().back()

def go_forward(self):
"""Simulates the user clicking the "forward" button on their browser."""
self._current_browser().forward()

def go_to(self, url):
"""Navigates the active browser instance to the provided URL."""
self._info("Opening url '%s'" % url)
self._current_browser().get(url)

 

 

selenium.py(C:\Python27\Lib\site-packages\selenium),添加下面红色代码至go_back方法下面

  注:有时候这个文件会不存在,进行重新安装可以修复此问题。

def go_back(self):
"""
Simulates the user clicking the "back" button on their browser.

"""
self.do_command("goBack", [])

def go_forward(self):
"""
Simulates the user clicking the "forward" button on their browser.

"""
self.do_command("goForward", [])

 

 

 

 

Robot 添加chrome go_forward关键字,浏览器前进功能_python_02

 

Robot 添加chrome go_forward关键字,浏览器前进功能_python_03

添加后,可以看到关键字了。

Robot 添加chrome go_forward关键字,浏览器前进功能_python_04

 



举报

相关推荐

0 条评论