Robot Framework中Selenium2Library同一浏览器打开新标签页
时间: 2024-04-28 13:22:21 浏览: 189
RobotFramework+selenium2library
要在Robot Framework中使用Selenium2Library在同一浏览器中打开新标签页,可以使用`Open Browser`关键字来打开浏览器,并使用`Create Webdriver`选项来创建WebDriver对象。然后,可以使用`Go To`关键字打开第一个网页,使用`Execute Javascript`关键字在当前页面中打开新标签页,最后使用`Switch Window`关键字切换到新标签页。下面是一个示例:
```
*** Settings ***
Library Selenium2Library
*** Test Cases ***
Open New Tab
Open Browser https://www.google.com chrome
${window handle} Get Window Handles
Go To https://www.robotframework.org/
Execute Javascript window.open("https://www.python.org/")
${new handle} Wait Until Keyword Succeeds 5s 1s Get New Handle
Switch Window ${new handle}
Title Should Be Python.org
Close Window
Switch Window ${window handle}
Title Should Be Robot Framework
Close Browser
*** Keywords ***
Get New Handle
[Return] ${set(${Get Window Handles})}-${get handle}
阅读全文