find_element(By.XPATH) not working python selenium
I'm trying to select the input
using the text at the bottom " 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 ?
Solution 1:
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[contains(.,'hello world')]
If it's the input
child of the above p
elements that you actually want, simply append /input
.