【问题标题】:How to get attribute from the class in xpath如何从xpath中的类获取属性
【发布时间】:2016-01-06 19:55:20
【问题描述】:

我有这个 HTML 代码:

<ul id="globe-welcome" class="fr nav welcome">
<li class="guest" style="display: list-item;">
 <a class="loginlnk">LOGIN</a></li></li></ul>

我想选择带有文本Auto 的标签选项标识的WebElement。我试过这个:

driver.findElement(By.xpath("//a[contains(@class,'loginlnk')]"))

我遇到了这个错误:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"/select[@id=category]/option[@id=cat2]"} 

Command duration or timeout: 1.52 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html

我尝试了另一个 xpath。

什么是正确的语法?有人可以帮我吗?

【问题讨论】:

    标签: javascript java selenium xpath


    【解决方案1】:

    尝试使用下面的xpath

    driver.findElement(By.xpath("//a[contains(text(),'LOGIN')]"))
    

    【讨论】:

      猜你喜欢
      • 2015-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-21
      • 1970-01-01
      • 2012-07-18
      • 2021-10-04
      • 2017-10-15
      相关资源
      最近更新 更多