【问题标题】:Robot Framework-Locator not found-Ebay websiteRobot Framework-Locator not found-Ebay 网站
【发布时间】:2021-10-25 03:59:15
【问题描述】:

我正在尝试使用 ebay 网站制作一个小型机器人框架,但每次我在 Click Element 中找不到定位器时,我都会尝试一切,甚至是睡眠并等待元素可见。我的代码就是这个。

*** Settings ***
Documentation  Basic Search Functionality
Library  SeleniumLibrary
*** variables ***

*** Test Cases ***
Verify basic search functionality
    [documentation]  This test case verifies the basic search functionality
    [tags]  Functional

    Open Browser  http://www.ebay.com  chrome
    Maximize Browser Window
    Input Text  //*[@id="gh-ac"]  mobile
    Press Keys  //*[@id="gh-btn"]  [Return]
    Page Should Contain  results for mobile
    Sleep  10s
    Wait Until Element Is Visible  xpath=//* 
    [@id="nid-pZ5-4"]/button/span
    Click Element  xpath=//*[@id="nid-pZ5- 
    4"]/button/span
    Close Browser

元素在图片中。 The element I am trying click it can be seen in the picture

【问题讨论】:

    标签: python xpath robotframework


    【解决方案1】:

    这个xpath

    xpath=//*[@id="nid-pZ5-4"]/button/span 
    

    看起来确实正确。因为我在 UI 中找不到任何元素。

    试试这个:

    xpath = //span[text()='Condition']/ancestor::button
    

    【讨论】:

    • 天哪,你太棒了。有用。我可以问你是什么问题吗?你怎么知道这行得通?
    • 听起来不错!您使用的定位器不正确,//*[@id="nid-pZ5- 4"]/button/span,我认为由于后端响应调用,每次运行时 id 都会改变。
    • 你做了什么来找到正确的 xpath 以便我以后可以复制?我正在 e-bay 上做测试,所以将来我可能会遇到同样的问题
    • 啊,xpath是个技巧,可惜没有工具可以生成相对xpath,你得学习xpath的写法。我会推荐这个w3schools.com/xml/xpath_axes.asp
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-04
    • 2021-04-16
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多