我正在嘗試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')]")
你有什么建議嗎?
uj5u.com熱心網友回復:
改變:
//p[contains(text(),'hello world')]
到:
//p[text()[contains(.,'hello world')]]
或者,如果目標可能包含在另一個元素中,請測驗p元素的字串值:
//p[contains(.,'hello world')]
如果它是您真正想要input的上述p元素的子元素,只需 append /input。
uj5u.com熱心網友回復:
如果 p 是您可以使用的唯一唯一元素(盡管幾乎從來沒有這種情況),我會得到這個 p(使用 agly xpath 或 findElements)并使用 getText 來獲取這個 p 的文本。然后您將能夠看到 Selenium 看到的文本。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/414627.html
標籤:
