首页 文章

机器人框架,镀铬新标签问题

提问于
浏览
0

我有一个简单的机器人框架脚本

*** 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 时,它会打开一个新选项卡,我的机器人脚本会失败 . 我怎样才能纠正它 . 请帮忙

1 回答

  • 3

    您可以使用select window关键字和 Get Window Titles 关键字在它们之间导航 Get Window Titles 关键字将返回 Headers 列表,该列表中的最后一个索引是已打开的新选项卡,要从列表中访问它,您可以执行以下操作 ${Tabs[1]} (如在此代码中,列表中只有2个值)

    *** 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
    

    我更改了代码的最后一行,因为它不是有效的文本 . 请参阅代码中的注释 .

相关问题