Home > database >  find_element(By.XPATH) not working python selenium
find_element(By.XPATH) not working python selenium

Time:01-17

I'm trying to select the input using the text at the bottom " hello world "

<p>
"test"
<label for="q906318:1_answer" >
Answer
</label>
<input type="text" name="q906318:1_answer" id="q906318:1_answer" size="11"  readonly="readonly">
<i  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 ?

CodePudding user response:

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.

CodePudding user response:

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. Then you'll be able to see the text as Selenium sees it.

  •  Tags:  
  • Related