3
这是很常见的情况,我的硒脚本将被运行,然后突然将与错误崩溃:无法在硒中找到元素时设置默认异常处理程序?
<class 'selenium.common.exceptions.NoSuchElementException'>
Message: u'Unable to locate element: {"method":"id","selector":"the_element_id"}'
<traceback object at 0x1017a9638>
如果我在交互模式下运行(蟒蛇-i myseltest.py)如果我只是做这样的事情:
driver.switch_to_window(driver.window_handles[0])
,然后再次运行特定的find_element_by_id()
,它会成功。
如果发生异常,有没有办法自动尝试driver.switch_to_window()
调用?
这绝对是最好的解决方案。谢谢。 – 2012-03-07 00:33:56