Selenium代码在driver.get之后没有执行

时间:2018-03-08 08:10:44

标签: python-3.x selenium automation automated-tests

我正在尝试自动化网站。我使用驱动程序,get()访问该页面并执行了一些操作。接下来我必须导航到该网站中的某个页面并使用driver.get()访问这个。在执行脚本工作到那个部分,发布它只是停止并且没有事件做一个打印状态。最后我得到一个超时异常。我无法弄清楚它在哪里失败。

```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:代码 代码中要自动运行的部分,直到此处 表示我使用了所有功能,直到此处它们正在工作。还在最后一个驱动程序中。 get()用户导航到所需的页面。此后脚本暂停。

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。在我的设置中,driver.get(URL)会不时随机失败。

要检测到成功的页面加载或强制超时到driver.get(URL),我使用以下解决方案,它适用于我:

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
相关问题