0

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')]"}
2
  • 1
    There could be several reasons for this error. Could you provide the complete html or a link it? Commented Mar 6, 2020 at 19:35
  • link this is the page, is to fill the input. Commented Mar 6, 2020 at 19:43

2 Answers 2

3

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")
Sign up to request clarification or add additional context in comments.

2 Comments

I think you typo'd the # in the ID... I'm assuming you were thinking CSS selector.
@JeffC You're right. Thanks! I usually use CSS selector 90%+ of the time and was running on auto pilot. Thanks for the edit!
1

//*[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"]

2 Comments

driver.find_element_by_xpath('//input[@id="txtNumDoc"]') That also gets error: Message: no such element: Unable to locate element: {"method":"id","selector":"//input[@id="txtNumDoc"]"}
if you are using id method then please send textNumDoc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.