我无法在 Selenium WebDriver 中找到以下代码的 gettext
。
<a id="551" class="blueTextNormal1 spc" onclick="sPh(this,'079');return false;" title="079">Country</a>
我想获得国家的价值。我尝试使用 xpath
:
driver.findElement(By.xpath("//*[@id='551']").getText())
但它没有返回任何值。当我尝试
driver.findElement(By.xpath("//*[@id='551']")).getAttribute("title"))
我得到的值为“079”。
我该如何进行?
原文由 Learner 发布,翻译遵循 CC BY-SA 4.0 许可协议
这也取决于代码。试试下面的代码:
而不是
getText()
,请使用getAttribute("innerHTML")
然后它将返回您要查找的内容,包括任何不可见的 HTML。我一直在寻找
Please select a doc
,但我没有成功getText()
。但是下面的一个有效。