【问题标题】:Selenium code not executing after driver.get在 driver.get 之后硒代码不执行
【发布时间】:2018-08-16 12:32:03
【问题描述】:

我正在尝试自动化网站。我使用 driver,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() 用户被导航到所需的页面。在此之后脚本会暂停。

【问题讨论】:

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


    【解决方案1】:

    我遇到了同样的问题。在我的设置中,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
    

    【讨论】:

    • 没有 driver.get 工作,我也看到了新页面...之后执行被暂停并且一段时间后看到超时异常。
    • 请编辑您的问题并发布输出。如果我的回答对你有帮助,请采纳
    • 我已经正确添加了描述...请查看。
    • 把我的代码放到一个单独的def中,并捕获超时异常。您可以将不起作用的 URL 保存在单独的列表中,然后再次循环遍历列表
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多