使用之前所需环境
SeleniumLibrary, chrome驱动
安装:pip install robotframework-seleniumlibrary==3.0.0
下载chrome浏览器对应驱动
找不到和chrome浏览器所匹配的版本,可以找版本相差不多的启动
比如浏览器版本是95.0.4638.69,可以去找95.0.4638.54相应的驱动:
robotframework-seleniumlibrary安装好了在ride中的测试案例导入SeleniumLibrary扩展库
打开浏览器
Open Browser https://baidu.com chrome
设置睡眠时间
强制等待(Sleep 5)
显示等待(Set Browser Implicit Wait 10)
窗口最大化
Maximize Browser Window
设置窗口位置
Set Window Position 20 40
返回上一步
Go Back
跳转
Go To http://www.baidu.com
刷新
Reload Page
定位元素的方式
还有个Select Window By Handle
使用前要在winwindowmanager.py和browsermanagement.py添加一下内容
winwindowmanager.py 路径
python\Lib\site-packages\SeleniumLibrary\locators\windowmanager.py
def select_by_handle(self, browser, toHandle):
browser.switch_to_window(toHandle)
def get_window_handles(self, browser):
return [ window_info[0] for window_info in self._get_window_infos(browser) ]
def get_current_window_handle(self, browser):
return browser.get_current_window_handle()
browsermanagement.py路径
python\Lib\sitepackages\SeleniumLibrary\keywords\browsermanagement.py
@keyword
def select_window_by_handle(self, locator=None):
self._window_manager.select_by_handle(self.drivers.current, locator)
@keyword
def get_window_handles(self):
"""Returns and logs handles of all windows known to the browser."""
return self._log_list(self._window_manager.get_window_handles(self.drivers.current))
@keyword
def get_current_window_handle(self):
"""Returns and logs handle of current window known to the browser."""
return self._log_list(self._window_manager.get_current_window_handle(self.drivers.current))