css - 使用 StoreValue 时,Selenium 声明 "This element has no value"

标签 css selenium

我有以下代码,我需要在其中获取值:

<a href="/checkout/cart.jsf">
Items: 
<span class="numberofitems">1</span>
</a>

但是,当我尝试使用 css=span [class='numberofitems'] 指向它时,我收到消息“该元素没有值;它真的是一个表单域吗?”该元素确实有一个我可以在 Firebug 中看到的值,但我不知道如何正确存储这个值。

最佳答案

开始吧.. 下面给出的每个 WebElements 都会给出更好的结果以获得值 '1'

By.xpath("//a[@href='/checkout/cart.jsf']/span")

By.xpath("//a[text()='Items: ']/span"))

By.xpath("//span[@class='numberofitems']")

如果他们不工作,

  1. 在 Firebug 的帮助下检查元素是否隐藏。
  2. 检查类名'numberofitems'是否重复。

关于css - 使用 StoreValue 时,Selenium 声明 "This element has no value",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18808876/

相关文章:

JavaScript/jQuery : Animated Cursor/Light Effect

css - 如何让 flex 元素扩展以适应居中的 flex 盒,直到达到一定的最大宽度?

java - org.testng.TestNGException : Cannot instantiate class

python - 如何修复 "WebDriverException: Message: connection refused"?

html - 在 RaphaelJS 中自动将文本换行到一定宽度?

html - 引导表 : how to vertical align the detail-icon?

html - 如何让一个移动的 div 里面有一个固定覆盖的元素?

python - NoSuchElementException : Message: Unable to locate element: [id ="j_username"] attempting WebdriverWait

Python Selenium 下拉菜单选择

python - 在 Python 中使用 Selenium 不要等待页面加载