0

i'm trying to load url https://www.eurexchange.com/exchange-en/products/idx/stx/blc/EURO-STOXX-50-Index-Options-46548

however some of the page get infinite loading recently and the time.sleep() function with a selenium.webdriver.execute_script('window.stop()') doesn't sovle the problem.

tried:

browser.execute_script('window.stip()')
and browser.find_element_by_tag_name("body").sendkeys(Keys.ESCAPE)

still see the page loading.

website_url = 'https://www.eurexchange.com/exchange-en/products/idx/stx/blc/EURO-STOXX-50-Index-Options-46548'
browser = webdriver.Chrome(executable_path=chromedriver_path, options=chrome_options)
dropdown = Select(browser.find_element_by_xpath('//*[@id="maturityDate"]'))
dropdown_len = len(dropdown.options)

for i in range(1, dropdown_len):
    rows = []
    time.sleep(2)
    browser.execute_script('window.stop()')
    # browser.find_element_by_tag_name("body").sendkeys(Keys.ESCAPE)
Mobrine Hayde
  • 365
  • 1
  • 2
  • 10
mojop
  • 41
  • 6
  • what i have to do is manually press the cross 'x' in chrome browser to kill the loading then the code move to next drop down work. – mojop Sep 11 '19 at 12:44
  • just to make sure are you putting `browser.execute_script('window.stip()')` in your script instead of `browser.execute_script('window.stop()')`?? – Mobrine Hayde Sep 11 '19 at 12:48
  • yes, my code snapshot is exactly what i put there. – mojop Sep 12 '19 at 14:27

2 Answers2

0

I believe you're looking for the WebDriverWait method, this allows you to specify a timeout wait for an element to be present in the page and if it doesn't appear within the time allocated, you can kill the script or whatever action you wish to take.

The example is from Selenium's Python documentation

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()
driver.get("http://somedomain/url_that_delays_loading")
try:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, "myDynamicElement"))
    )
finally:
    driver.quit()
Lucan
  • 2,907
  • 2
  • 16
  • 30
0

You can use a timeout for not waiting forever

browser.implicitly_wait(60) # 60 seconds to wait && this is only used with chrome
browser.set_page_load_timeout(60) # for other browsers

This will throw an exception so you need to do a try except statement like:

browser.implicitly_wait(60)

try:
    browser.get('http://www.example.com')
except:
    print "loading exceeded the time limit" # not sure what python version you are using
Mobrine Hayde
  • 365
  • 1
  • 2
  • 10
  • it works for the first few drop down box selection, then it still keep loading after 4 drop down box refresh. i used browser.implicitly_wait(3) – mojop Sep 12 '19 at 13:59