0

I need help, selenium Chrome getting stuck at some pages while browsing,

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
#options.add_argument('--no-sandbox')
options.add_argument("disable-infobars")
options.add_argument('--disable-browser-side-navigation')
options.add_argument("--start-maximized")


driver = webdriver.Chrome(chrome_options=options)
driver.set_page_load_timeout(10)

this how I make the driver, however it is definetly getting stuck on some pages for more than 300s (I have to Ctrl+C) to get it to keep moving (inside a for loop)

programmerwiz32
  • 529
  • 1
  • 5
  • 20
  • Page load timeout is global and will happen whenever a page starts loading and pageready state does not occur within the time set. (And I believe the DOM will be blank at that point... so every test afterwards will fail until another page loads...) If a page is infinitely loading, that is a bug on the site and it should be fixed. 10 seconds is probably a little too short to show that this is a page that is taking too long to load. Also remember that page load timeout will not come into play for pages that update the DOM purely via javascript. – pcalkins Jul 29 '19 at 20:29
  • @pcalkins what can I do then to fix, the links are gather from different websites ( I can't know beforehand which will cause issue) – programmerwiz32 Jul 29 '19 at 20:37
  • @pcalkins is there anything code in the code I can do to fix it? – programmerwiz32 Jul 29 '19 at 20:38
  • as far as I know, there is not... after timeout you can't do anything with the page because it hasn't loaded... and Selenium is not refreshed. The only thing I can think of is to trigger the pageready state yourself. You'd have to do that outside of Selenium, because it won't have a page to inject a script into. There's mention of setting the pageloadstrategy here though I've never tried this ("eager" might help if it's trying to load linked resources): https://stackoverflow.com/questions/43734797/page-load-strategy-for-chrome-driver-updated-till-selenium-v3-12-0 – pcalkins Jul 29 '19 at 21:57
  • I've found that setting this option in ChromeDriver can help in certain cases: options.addArguments("--dns-prefetch-disable"); – pcalkins Jul 29 '19 at 22:00

0 Answers0