【发布时间】:2021-01-06 11:31:05
【问题描述】:
我正在编写一个使用 Firefox webdriver 的 python 脚本。但是,在满足条件之前不应创建浏览器实例。
在测试浏览器是否已经打开时,Spyder 的编辑器中有一条消息:undefined name 'driver'。
如何更改代码以消除该消息?
while True
if time_to_work():
if driver.service.is_connectable():
do_something()
else:
driver = webdriver.Firefox(profile, options=options)
print('Browser started..')
else:
if driver.service.is_connectable():
print('Closing browser..')
driver.quit()
【问题讨论】:
-
你用
is_connectable测试什么条件? -
@Mike67 我想知道是否需要创建浏览器实例。或者它已经存在,准备获取网页。
标签: python python-3.x python-2.7 selenium-firefoxdriver