无法使用Java中的Selenium捕获文本
我正在使用Java中的Selenium从以下代码段中捕获值。但这是返回无效的值。
<div class="selenium" style="max-height: 0px !important; max-width: 0px !important;">
<div class="share metric">
<span id="nsf" class="nsf">
"2.2210636079249215+2.224479431183342+2.2244191794364805+2.2635962763351296+2.289855072463768+2.3309352517985613+2.3216783216783217+2.360018509949098+null+2.042235790730032+0.000006222369997702123+0</span></div>
我尝试使用
driver.findElement(By.xpath("//div[@class='share metric']/span[@id='nsf']")).getAttribute("value")
并
driver.findElement(By.xpath("//div[@class='share metric']/span[@id='nsf']")).gettext()
I am using Selenium in Java to capture values from the below code snippet. But it's returning a null value.
<div class="selenium" style="max-height: 0px !important; max-width: 0px !important;">
<div class="share metric">
<span id="nsf" class="nsf">
"2.2210636079249215+2.224479431183342+2.2244191794364805+2.2635962763351296+2.289855072463768+2.3309352517985613+2.3216783216783217+2.360018509949098+null+2.042235790730032+0.000006222369997702123+0</span></div>
I tried using
driver.findElement(By.xpath("//div[@class='share metric']/span[@id='nsf']")).getAttribute("value")
and
driver.findElement(By.xpath("//div[@class='share metric']/span[@id='nsf']")).gettext()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的XPath是错误的,跨度标签不是
&lt; div class =“ share Metric”&gt;
的孩子。为什么完全使用XPATH?通过其
ID
局部局部局部效果很好。代码:
输出:
Your xpath is wrong, the span tag is not a child of
<div class="share metric">
.Why using xpath at all? Localting the element by it's
id
works just fine.code:
output: