[英]find_element(By.XPATH) not working python selenium
I'm trying to select the input
using the text at the bottom " hello world "
我正在尝试
input
使用底部的文本" hello world "
输入
<p>
"test"
<label for="q906318:1_answer" class="accesshide">
Answer
</label>
<input type="text" name="q906318:1_answer" id="q906318:1_answer" size="11" class="form-control d-inline incorrect" readonly="readonly">
<i class="icon fa fa-remove text-danger fa-fw " title="Incorrect" aria-label="Incorrect">
::before
</i>
" hello world "
</p>
but I can't use the但我不能使用
driver.find_element(By.XPATH, "//p[contains(text(),'hello world')]")
Have you any suggestions?你有什么建议吗?
Change改变
//p[contains(text(),'hello world')]
to至
//p[text()[contains(.,'hello world')]]
or, if the target may be wrapped in another element, test the p
element's string value:或者,如果目标可能包含在另一个元素中,请测试
p
元素的字符串值:
//p[contains(.,'hello world')]
If it's the input
child of the above p
elements that you actually want, simply append /input
.如果它是您真正想要的上述
p
元素的input
子元素,只需 append /input
。
If the p is the only unique element you can use(though it's almost never the case), I would get to this p(with agly xpath or with findElements) and use getText to get the text of this p.如果 p 是您可以使用的唯一唯一元素(尽管几乎从来没有这种情况),我会得到这个 p(使用 agly xpath 或使用 findElements)并使用 getText 获取此 p 的文本。 Then you'll be able to see the text as Selenium sees it.
然后您将能够看到 Selenium 看到的文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.