Selenium can't set text

Viewed 53

Here is form element on the page

<input class="step__input" valid="true" id="capture-first-name" data-capture-id="first-name" name="first-name" placeholder="First Name" type="text" minlength="2" autocomplete="given-name" maxlength="32" pattern="((?!(\s{2})).){2,32}" autocapitalize="on">

When I do this...

browser.find_element_by_xpath('capture-first-name').send_keys('Adam')

I get error

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"capture-first-name"}
(Session info: chrome=92.0.4515.159)

How can I fix this?

1 Answers

That's an id.

You should use

browser.find_element_by_id('capture-first-name').send_keys('Adam')

instead of by_xpath

In case you wanna stick with xpath

browser.find_element_by_xpath("//input[@id='capture-first-name']").send_keys('Adam')
Related