在 driver.get 之后硒代码不执行 [英] Selenium code not executing after driver.get

查看:26
本文介绍了在 driver.get 之后硒代码不执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使网站自动化.我使用 driver,get() 访问该页面并执行了一些操作.接下来我必须导航到该网站中的某个页面并使用 driver.get() 访问这.在执行脚本时,直到该部分,发布它只是停止并且不执行打印语句.最后我得到一个超时异常.我无法弄清楚它失败的地方.

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:代码中的部分在此之前运行良好的代码部分表明我使用了直到这里的所有功能并且它们正在工作.也在最后一个驱动程序中.get() 用户被导航到所需的页面.在此之后脚本会暂停.

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.

推荐答案

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

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

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

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

这篇关于在 driver.get 之后硒代码不执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆