【问题标题】:RobotFramework: Switching window after clicking into a new windowRobotFramework:点击进入新窗口后切换窗口
【发布时间】:2017-12-01 12:26:44
【问题描述】:

在单击指向 RobotFramework 中第二个窗口的链接后,有没有办法调整第二个窗口的焦点(即移到前面)?我有一些代码在点击后进行截图,它只显示第一个窗口

Click link  xpath=//*[contains(., "Download certificate")]
sleep  20
Select Window    Title=Certificate
Page Screenshot  Completion-Certificate   

我知道弹出窗口的标题是证书,但我收到错误

ValueError: Unable to locate window with title 'Certificate'    

【问题讨论】:

    标签: robotframework


    【解决方案1】:

    是的,您可以通过添加以下脚本来做到这一点-

    Switch Window  locator=NEW
    //This will take you to the latest window launched.
    

    它对我有用。

    【讨论】:

      【解决方案2】:

      我认为,您正在尝试测试单击链接时出现的弹出窗口。您可以使用以下解决方案,

      Select Window    ${windowId}    # Focus popup/required window
      

      【讨论】:

        【解决方案3】:

        我认为对于您的情况,以下将满足要求:

        Select Window    locator=Certificate
        

        【讨论】:

          【解决方案4】:
          Handle Lookup Window
          Select Window    NEW      #comment: It will automatically move to new window
          ${tempB}=    Get Title
          Log To Console    New window is : \ ${tempB}    # to verify the name in console
          Select Frame    //*[@title='Search']            # optional sometimes elements are within frames ,so first need to access frame
          Input Text    id=lksrch    hello
          Click Element    //*[@value=' Go! ']
          Unselect Frame                                  # going back to page
          Select Frame    //*[@title='Results']           #selecting another frame
          Click Element    id=jobdone 
          Select Window                                    #once the jobdone button is clicked my pop up browser window is automatically get closed.so going back to parent browser.
          

          注意:使用 # 开头的行是 cmets,仅用于理解目的 谢谢!

          【讨论】:

          • "Handle Lookup Window" 是您必须创建的测试用例/关键字名称。除了第 1 行,请给所有的 4 个空格作为缩进。
          【解决方案5】:

          您可以通过标题、URL 或窗口句柄 ID 切换到多个窗口。为此,请使用 Robot Framework 中的“选择窗口”关键字。

          示例 1:

          open browser  http://qaTechTesting.com Chrome
          click element  (//img[@alt='Raghwen Linkedin Profile'])[1]
          Select Window  Raghwendra Sonu
          

          示例 2:

          open browser  http://qaTechTesting.com Chrome
          click element (//img[@alt='Raghwen Linkedin Profile'])[1]
          @{list1}  get window handles
          :FOR  ${Win} in ${list1}
          \  Select Window   ${Win}
          

          更多详情请阅读:http://robotframework.org/Selenium2Library/Selenium2Library.html#Select%20Window

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2018-04-15
            • 2020-10-15
            • 2012-05-04
            • 2017-11-25
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多