Locate an fill input element with selenium python

I'm Trying to fill the next txtBox but I'have tried with the xpath, name, class.

<input name="txtNumDoc" type="text" id="txtNumDoc" class="txtBox">

But always get me the same error.

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[contains(.,'txtNumDoc')]"}

Upvotes: 0

Views: 524

Answers (2)

RKelley
RKelley

Reputation: 1119

First, the element you are trying to access is inside an iframe so you need to switch to that first:

iframe = driver.find_element_by_id("iframeBDUA")

driver.switch_to.frame(iframe)

and then you can find your element:

element = driver.find_element_by_id("txtNumDoc")

Upvotes: 3

supputuri
supputuri

Reputation: 14135

//*[contains(.,'txtNumDoc')] is not a valid xpath for this element as we don't have text txtNumDoc for this element. txtNumDoc is attribute value for both name and id in this case.

use the below.

//input[@id="txtNumDoc"]

Upvotes: 1

Related Questions