【问题标题】:unable to find the element in my application using selenium webdriver无法使用 selenium webdriver 在我的应用程序中找到元素
【发布时间】:2017-04-18 17:29:57
【问题描述】:

元素的HTML代码是:

<select id="pt1:reg2:1:soc1::content" class="x2h" title="" theme="dark" name="pt1:reg2:1:soc1">

每次 xpath 发生变化但我无法找到元素。

WebElement w1 = driver.findElement(By.xpath(".//select[starts-with(@id, 'pt1') AND contains(@id, ':soc1::content')]"));
Select s = new Select(w1);
s.selectByVisibleText("Commercial");

【问题讨论】:

  • 使用编辑器上方的括号图标将代码与文本分开。

标签: selenium selenium-webdriver


【解决方案1】:

我使用在线工具测试了 xpath,例如:http://www.xpathtester.com/xpath 这个查询工作得很好,我把 and 改成了小写。

 .//select[starts-with(@id, 'pt1') and contains(@id, ':soc1::content')]

【讨论】:

  • 如果我的回答确实回答了你的问题,如果你检查了答案,我会很合适。这将有助于未来的人们快速找到正确的答案。有关答案的更多信息:meta.stackexchange.com/a/5235
【解决方案2】:

用双引号“xpath here”写 Xpath 和 不要使用第一个句号'。来自 xpath,它没有用。
它以 //

开头

祝你好运

【讨论】:

    【解决方案3】:
    ".//select[starts-with(@id, 'pt1') AND contains(@id, ':soc1::content')]"
    

    这里的句号(.) //需要在Xpath中去掉。

    【讨论】:

      【解决方案4】:

      下面一个没有“AND”,它也可以正常工作。

      //select[starts-with(@id, 'pt1')][contains(@id,':soc1::content')]
      

      【讨论】:

        猜你喜欢
        • 2017-08-18
        • 1970-01-01
        • 1970-01-01
        • 2016-08-31
        • 2023-04-01
        • 1970-01-01
        • 2015-05-04
        • 1970-01-01
        • 2014-05-29
        相关资源
        最近更新 更多