簡體   English   中英

find_element(By.XPATH) 不工作 python selenium

[英]find_element(By.XPATH) not working python selenium

我正在嘗試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>

但我不能使用

driver.find_element(By.XPATH, "//p[contains(text(),'hello world')]")

你有什么建議嗎?

改變

//p[contains(text(),'hello world')]

//p[text()[contains(.,'hello world')]]

或者,如果目標可能包含在另一個元素中,請測試p元素的字符串值:

//p[contains(.,'hello world')]

如果它是您真正想要的上述p元素的input子元素,只需 append /input

如果 p 是您可以使用的唯一唯一元素(盡管幾乎從來沒有這種情況),我會得到這個 p(使用 agly xpath 或使用 findElements)並使用 getText 獲取此 p 的文本。 然后您將能夠看到 Selenium 看到的文本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM