So I am trying to use selenium to automate some form completion, but I'm running up against an issue. One of the forms I am using is not loaded straight away by the HTML, but it is loaded using JavaScript after the page has loaded normally. For whatever reason, selenium isn’t able to see the updated source of the page after it loads in the javascript. For example, if I run the following code.
browser = webdriver.Firefox()
browser.get('https://examplepage.com')
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.ID, “13jres”))).send_keys(“email@email.com”)
Nothing happens and it times out. After doing some testing I've noticed that if I print the source code in python, using the following code
browser = webdriver.Firefox()
browser.get('https://examplepage.com')
time.sleep(20)
print browser.page_source
Then the source code is different than the source code which I can view manually in the selenium firefox instance. So the following line, which is what I am trying to put an input into, isn't there according to the selenium source output, even though its obviously in there when inspecting element in firefox or viewing the source in Firefox instance of what was loaded using selenium.
<input label=“Email” type="text" name="13jres" id="13jres" class="text-field”>(shortened to make it more readable)
Reading through some docs I found this tidbit when referencing the page_source command, which I guess explains the difference in the sources, but I am still unclear on how to alleviate my issue with finding these elements on the page. I've tried other browsers in selenium(safari, chrome, etc) but besides that, I'm not really sure what I need to do.
“If the page has been modified after loading (for example, by Javascript) there is no guarantee that the returned text is that of the modified page. Please consult the documentation of the particular driver being used to determine whether the returned text reflects the current state of the page or the text last sent by the web server.”