robotframework 切换浏览器窗口
selenium2library提供的切换到新窗口的关键字,只有select window,而且也只能根据title、name、url去定位。
如果存在title、name、url都有相同的值就无法通过select window切换窗口
所以就需要拓展selenium2library库,即修改selenium的源码。
-
*\ Python27\Lib\site-packages\SeleniumLibrary\locators:找到windowmanager.py文件。
打开编辑,增加方法
def select_by_handle(self,browser,tohandle): browser.switch_to_window(tohandle)
2.*\ Python27\Lib\site-packages\SeleniumLibrary\keywords: 找到window.py文件。
打开编辑,增加方法
@keyword
def select_window_by_handle(self, locator=None):
self._window_manager.select_by_handle(self.drivers.current, locator)
修改完保存后就可以用select window by handle关键字来切换浏览器窗口了
${b} get window handles #获取所有窗口的句柄
select window by handle ${b}[1] #选择第二个句柄的窗口
robotframework 切换浏览器窗口
selenium2library提供的切换到新窗口的关键字,只有select window,而且也只能根据title、name、url去定位。
如果存在title、name、url都有相同的值就无法通过select window切换窗口
所以就需要拓展selenium2library库,即修改selenium的源码。
-
*\ Python27\Lib\site-packages\SeleniumLibrary\locators:找到windowmanager.py文件。
打开编辑,增加方法
def select_by_handle(self,browser,tohandle): browser.switch_to_window(tohandle)
2.*\ Python27\Lib\site-packages\SeleniumLibrary\keywords: 找到window.py文件。
打开编辑,增加方法
@keyword
def select_window_by_handle(self, locator=None):
self._window_manager.select_by_handle(self.drivers.current, locator)
修改完保存后就可以用select window by handle关键字来切换浏览器窗口了
${b} get window handles #获取所有窗口的句柄
select window by handle ${b}[1] #选择第二个句柄的窗口