1

I currently click a button into a new window:

browser.execute_script("arguments[0].value = 'test';", browser.find_element_by_xpath('//*[@id="email-signup-email-address"]'))
input_button = browser.find_element_by_xpath('//*[@id="submittracking"]')
browser.execute_script('arguments[0].target="_blank";', input_button.find_element_by_xpath('./ancestor::form'))
browser.execute_script('arguments[0].click();', input_button)

but must time.sleep(10) before asking browser.page_source otherwise the page does not load fully

Other articles/posts suggest to use seleniums explicit wait but this asks to provide an element to wait for such as visibilityOfAllElements() or some specific element. I would like to get the ALL the page_source and am not looking to identify any elements.

How can I make browser.page_source work as it normally does (when not clicking into a new window)?

2
  • 1
    you can wait until state is completed, see this stackoverflow.com/questions/5868439/… Commented Dec 18, 2018 at 8:28
  • Do you mean, readyState? I may look into this further. Curious if it has a timeout built in. Also the link is mostly in Java Commented Dec 18, 2018 at 8:39

2 Answers 2

1

Try to wait for page loaded (document.readyState == 'complete') as below:

from selenium.webdriver.support.ui import WebDriverWait

WebDriverWait(browser, 20).until(lambda browser: browser.execute_script("return document.readyState;") == "complete")
Sign up to request clarification or add additional context in comments.

Comments

0

You can use some timeout for the page load like below:

driver.set_page_load_timeout(30)

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.