栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

selenuim驱动IE浏览器报错selenium.common.exceptions.NoSuchWindowException: Message: Currently focused window

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

selenuim驱动IE浏览器报错selenium.common.exceptions.NoSuchWindowException: Message: Currently focused window

selenuim驱动IE浏览器报错:selenium.common.exceptions.NoSuchWindowException: Message: Currently focused window has been closed.
  • selenuim驱动IE浏览器报错:selenium.common.exceptions.NoSuchWindowException: Message: Currently focused window has been closed.
      • 问题原因&解决:
      • 注意

selenuim驱动IE浏览器报错:selenium.common.exceptions.NoSuchWindowException: Message: Currently focused window has been closed.
selenium.common.exceptions.NoSuchWindowException: Message: 
Currently focused window has been closed.
D:Anacondaseleniumwebdrivererrorhandler.py:242: NoSuchWindowException
问题原因&解决:
电脑无法在页面自动跳转之后,获取当前页面。
window handle是惰性的,不会自动切换,如果打开了一个新的窗口,想在新窗口上获取某一元素,
需要先手动切换window handle,driver.switch_to.window(xxx_handle)
另,用driver.window_handles可以获取所有窗口句柄
解决:
在跳转页面之后、定位元素之前添加:
handles = driver.window_handles
driver.switch_to.window(handles[-1])
time.sleep(5)
定位到当前窗口句柄,再进行元素定位。窗口句柄是浏览器拥有的,元素没有窗口句柄
注意
如果元素定位失败,要检查一下是不是打开了新的窗口,如果是,则需要切换window handle,
因为它不会自动切换。
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/977823.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号