Selenium代码在driver.get之后不执行 [英] Selenium code not executing after 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
这篇关于Selenium代码在driver.get之后不执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!