机器人框架,chrome 新标签问题 [英] Robot framework, chrome new tab issue
问题描述
我有一个简单的机器人框架脚本
I have a simple Robot Framework script
*** Settings ***
Documentation Simple Amazon.in demo
Library SeleniumLibrary
*** Variables ***
${MESSAGE} Hello, World
*** Test Cases ***
User must sign in to check out
[Documentation] This is some basic info about the test
[Tags] Smoke
Open Browser http://www.amazon.in chrome
Input text id=twotabsearchtextbox Ferrari 458
Click Button xpath=//div[@class='nav-search-submit nav-sprite']/input[@class='nav-input' and 1]
Wait until page Contains results for "Ferrari 458"
Click Link css=#result_0 a.s-access-detail-page
Wait until Page Contains Back to search results for "Ferrari 458"
Click Button id=add-to-cart-button
Wait Until Page Contains 1 item added to Cart
但是每当 chrome 到达 Click Link css=#result_0 a.s-access-detail-page
时,它会打开一个新选项卡,并且我的机器人脚本失败.我该如何纠正它.请帮忙
But whenever chrome reaches Click Link css=#result_0 a.s-access-detail-page
it opens a new tab, and my robot script fails. How can I rectify it. Please help
推荐答案
您可以使用 select window 关键字和 Get Window Titles
关键字在它们之间导航 Get Window Titles
关键字将返回一个标题列表,该列表中的最后一个索引是新的已打开的选项卡,要从列表中访问它,您可以执行以下操作 ${Tabs[1]}
(因为在此代码中列表中只有 2 个值)
You can use the select window keyword and Get Window Titles
keyword to navigate between them Get Window Titles
keyword will return a list of titles the last index in that list is the new tab that has been opened, to access it from the list you can do the following ${Tabs[1]}
(as in this code there is only 2 values in the list)
*** Settings ***
Documentation Simple Amazon.in demo
Library SeleniumLibrary
*** Variables ***
${MESSAGE} Hello, World
*** Test Cases ***
User must sign in to check out
[Documentation] This is some basic info about the test
[Tags] Smoke
Open Browser http://www.amazon.in chrome
Input text id=twotabsearchtextbox Ferrari 458
Click Button xpath=//div[@class='nav-search-submit nav-sprite']/input[@class='nav-input' and 1]
Wait until page Contains results for "Ferrari 458"
Click Link css=#result_0 a.s-access-detail-page
${Tabs} = Get Window Titles
select window title=${Tabs[1]}
Wait until Page Contains Back to search results for "Ferrari 458"
Click Button id=add-to-cart-button
# Wait Until Page Contains 1 item added to Cart
Wait Until Page Contains Added to Cart
结果:
==============================================================================
Amazon :: Simple Amazon.in demo
==============================================================================
User must sign in to check out :: This is some basic info about th...
DevTools listening on ws://127.0.0.1:29864/devtools/browser/75b8be3c-6e76-474f-b391-d340fb322895
User must sign in to check out :: This is some basic info about th... | PASS |
------------------------------------------------------------------------------
Amazon :: Simple Amazon.in demo | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: C:\development\robot-scripts\sssss\output.xml
Log: C:\development\robot-scripts\sssss\log.html
Report: C:\development\robot-scripts\sssss\report.html
我更改了您代码的最后一行,因为它不是有效文本.查看代码中的注释.
I changed the last line of your code as it wasn't a valid text. See the comment in the code.
这篇关于机器人框架,chrome 新标签问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!