简体   繁体   English

Selenium TimeoutException 与 Flask 和 Python

[英]Selenium TimeoutException with Flask and Python

This is what my code looks like这就是我的代码的样子

@app.route("/Committ", methods=['GET', 'POST']) 
def Committ():
  ......
  if(......):
    #do sthg
    firefox_profile = webdriver.FirefoxProfile()
    firefox_profile.set_preference("browser.priavtebrowsing.autostart",True)
    driver = webdriver.Firefox(firefox_profile = firefox_profile)
    driver.get("https://www.instagram.com")
    assert "Instagram" in driver.title
    ......
    driver.close()

After running the code above for a number a time usually at the 2nd or third time I get the following error:通常在第二次或第三次运行上面的代码一次后,我收到以下错误: 条件一

I try add a try and except to avoid this from happening but it didn't rly workout.我尝试添加一个尝试,除了避免这种情况发生,但它并没有真正锻炼。

未绑定本地错误

So it turned out to be a minor issue to cause the whole thing to fall apart, where when flask navigates to a page is like calling a function, everything would goes away when it leaves the page.所以结果证明是一个小问题导致整个事情分崩离析,当 flask 导航到一个页面时就像调用 function 一样,当它离开页面时一切都会消失。 However selenium always makes internal changes, thus I didn't properly closed the driver when I leave the function causing confusion when the function got called again!然而 selenium 总是进行内部更改,因此当我离开 function 时我没有正确关闭驱动程序,当再次调用 function 时造成混乱!

This is what I originally have:这是我原来拥有的:

...do sthg...
return redirect(url_for('home'))
driver.close()

A simple fix would be一个简单的修复方法是

...do sthg...
driver.close()
return redirect(url_for('home'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM