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

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

 

由上面可以分析得出,此关键字只是没有添加到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", [])

 

 

 

 

 

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

 

posted @ 2017-03-06 11:51  白灰  阅读(463)  评论(0)    收藏  举报