David Martins David Martins - 3 months ago 34
jQuery Question

Selenium Python : Unable to get element by id/name/css selector

For a school project, I'm trying to create a Python Script which is able to fill in different forms, from different websites.

Here is the thing, for some kinds of website, I'm not able to catch the form elements which Selenium.
E.g. in this website : http://www.top-office.com/jeu
Where I inspect the page with firefox, the input "Name" box has the id "lastname", but Selenium is not able to get it. And when I display the html code of this page, the form looks like being included from another page or something.

I tried to getelementbyid, byname, bycssselector, etc.
I also tried to wait for the page to be entirely loaded by using WebDriverWait(driver, 5), but it still do not work.

Do you have any solutions or suggestions ?

PS : Even with javascript, I'm not able to get this element by id



The element that you are trying to interact with is inside of an iframe. You need to use the driver.switch_to_frame() method in order to switch the driver to focus on that iframe. Only when it has switched into that iframe can it interact with its elements.

See this post on how to use it. You can locate the iframe using xpath, like this: //iframe[@src = 'https://adbx.me/grandjeuclubmed/']. Then, you can use the code mentioned in the post I gave you.