Python与Selenium:无效(?)警告
这是一个关于使用Python和Selenium的代码片段:
alert = driver.switch_to_alert().accept()
运行这段代码后,我得到了:
Warning (from warnings module):
File "C:\Python34\selenium\webdriver\remote\webdriver.py", line 517
warnings.warn("use driver.switch_to.alert instead", DeprecationWarning)
DeprecationWarning: use driver.switch_to.alert instead
我不太明白这个结果,难道我不是已经用driver.switch_to.alert了吗?
1 个回答
1
仔细看看你调用的方法名称,有的地方用下划线,有的地方用点。你现在使用的是你的 driver
对象里的 switch_to_alert()
方法,但看起来 Selenium 已经不再推荐这个方法了,而是让你用一个新的 switch_to
子类或属性。
所以你应该使用 driver
里的 switch_to
的 alert()
方法,而不是继续用 switch_to_alert()
。