0

I'm using Selenium to fill out this HTML form, but when it comes to inputting the data it says 'element not interactable'. I am able to click on the element however actually sending a string produces an error. How can I fix this?

driver.get('https://www.masmovil.es/cobertura-fibra-optica-campos/')
prov = Select(driver.find_element_by_xpath('//*[@id="province"]'))
prov.select_by_index(32)
driver.find_element_by_xpath('//*[@id="town"]').send_keys('1')

Thank you!

3 Answers 3

1

In the page you are accessing there are 2 elements that are returned with the selector by_xpath('//*[@id="town"]'), one is a "mm-ui-autocomplete", the other one is an "input".

the "mm-ui-autocomplete" is not visible nor interactable to a real user, that's probably what's throwing the exception you're having, and selenium always takes the first match when there's more than one element returned by the selector, so, assuming you want to type something on the "Localidad" field, it is selecting the wrong element.

Try changing your selector to by_xpath('//input[@id="town"]') and see if it works.

Hope it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

yes thank you! I feel so stupid, i had spent a while trying to figure that out.
1

Can you try with this css selector :

input[id='town']

code :

driver.find_element_by_css_selector("input[id='town']").send_keys('1')  

The xpath (//*[@id="town"]) you have used has two entries :

one with mm-ui-autocomplete tag and one with input tag.

Always give preference to css selector over xpath. It's more stable then xpath.

In case you would not want to use css selector, then you can use xpath like this :

//input[@id='town']  

Code :

driver.find_element_by_xpath("//input[@id='town']").send_keys('1')

Comments

0

In my case, it happens that the find_element was not working before the frontend finished loading.

I solved this by adding sleep(2) before the find_element_by_xpath. You will need to import the function by from time import sleep.

Comments

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.