Selenium code not executing after driver.get

2019-07-24 04:50发布

I am trying to automate a website.I used driver,get() to access the page and did a couple of actions.Next I had to navigate to a certain page in that website and used driver.get() to access this. On executing the script works till that part,post this it simply stops and does not event do a print statment.At the end I get a timeout exception.I am not able to figure out where it is failing.

```code to automate which works well until here```
guid="48bc1201-3929-42af-85cf-50e89b53a800"
#guid=guid

url=baseurl+"#/loan/{"+ str(guid) + "}/summary"

print("qqw" + url)
driver.get(url)

#print functionality also does not happen.Basically the code freezes

print("next execution")

PS: the portion in code code to automate which works well until here indicates that I used all functionalities until here and they were working.Also in the last driver.get() the user is navigated to the required page.After this the script kind of pauses.

1条回答
地球回转人心会变
2楼-- · 2019-07-24 05:14

I ran into the same issue. In my setup, driver.get(URL) fails randomly from time to time.

To detect a successful page load or to force a timeout to driver.get(URL), I employ the following solution and it works for me:

driver.set_page_timeout(n)
driver.set_script_timeout(n)
loading_finished = 0                    # URL not loaded
loading_attempts = 0                    # Count loading attempts
while loading_finished = 0:             # Enter loop 
    try:                         
        if loading_attempts > 5:        # Threshold for loading attempts
             print "URL loading failed"
             break                      # Too many loading attempts - exit loop
        else:
             website = driver.get(URL)  # Try to load URL
             loading_finished = 1       # URL loaded successfully - exit loop
             print "URL loading worked"
    except:
           loading_attempts += 1        # Loading failed - count failed attempt and retry
else:
     process_URL(driver, URL)           # Do your magic
查看更多
登录 后发表回答