1

I am not completely new to selenium but I cannot work this out. I am supposed to do a basket automation and I have troubles at the first page.

I am supposed to fill three input boxes at first to proceed to the actual order but I fail at the first input. We have unique ids for almost every input so it should not be too hard to find it but somehow it is.

<input class="form-input--text" data-validitytext-empty="Položka je povinná.<br>Prosíme, vyplňte ji." data-validitytext-invalid="Položka má špatný formát.<br>Prosíme, opravte ji." data-label-selector="closest(.form-item--required)->find(label.form-label)" id="surname003" name="Prijmeni" type="text" value="" data-form-required="true" xpath="1">

This is how the first input is described with id of "surname003" so my first try was to do this

driver.find_element_by_xpath("//*[@id='surname003']").send_keys("text")

Then I tried to access it with id

driver.find_element_by_id("surname003").send_keys("text")

Nothing from this was working so I tried to get the full xpath of it but that did not work.

This is how the code looks as a whole

driver = webdriver.Chrome(executable_path=r"C:\Users\KDK\Desktop\Selenium setup\chromedriver.exe")
driver.get(URL2)
driver.maximize_window()
driver.implicitly_wait(10) 
driver.find_element_by_xpath("//*[@id='surname003']").send_keys("test")
driver.find_element_by_xpath("//*[@id='phone03']").send_keys(telefon)
driver.find_element_by_xpath("//*[@id='email03']").send_keys(email)

This is the error I get

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element:

This is the page I am working with :

https://www.nev-dama.cz/zima/rakousko/lungau/residence-carpe-solem-mariapfarr/rezervaceNova?termin=2021-01-10&typologie=[26225]&delka=3

I am thinking if the issue of locating the element is somehow connected to the fact that you can switch between two "windows" in the reservation page. You can switch between "Not binding reservation" and "Buy online" and I dont know if that makes it somehow harder to get to the element.

I hope someone can help me with this. If something is not clear please ask me and thanks for reading and thanks in advance for some answers! :)

1 Answer 1

1

They have few inputs with the same id and first is from another from. But it mustn't raise NoSuchElementException. Try XPATH like that //div[@id="koupit-online"]//*[@id='surname003']. You need to add this part //div[@id="koupit-online"] to all all xpath or use as context

form = driver.find_element_by_xpath("//div[@id='koupit-online']")
form.find_element_by_xpath(".//input[@id='surname003']").send_keys("test")
form.find_element_by_xpath(".//input[@id='phone03']").send_keys(telefon)
form.find_element_by_xpath(".//input[@id='email03']").send_keys(email)

Second problem can be chromedriver. When i used chrome with selenium i got this exception without reason. I changed browser to firefox and geckodriver and this never happend again

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

1 Comment

Thank you so much it is working now! Interesting enough, whenever I try to reach the element via xpath the response I get is that the element is not interactable but when I define it as id it somehow works.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.