selenium - get() 后 Selenium 窗口句柄发生变化
问题描述
加载 html 文件后窗口句柄发生变化:
from selenium import webdriver
webDrv = webdriver.Firefox()
print("Window Handles after new webdriver: ", webDrv.window_handles)
新 webdriver 后的窗口句柄:['10']
# base tab used for another purpose and ignored here
# open a new tab
link = "about:blank"
webDrv.execute_script("window.open('{}');".format(link))
print("Window Handles after open blank tab: ", webDrv.window_handles)
打开空白选项卡后的窗口句柄:['10', '4294967298']
hdl = webDrv.window_handles[-1] # get the new handle
webDrv.switch_to.window(hdl) # switch to the new tab
webDrv.get(r"file://C:/BasePage.html") # open simple html
print("Window Handles after file load: ", webDrv.window_handles)
文件加载后的窗口句柄:['10', '24']
这里发生了什么?谁改变了句柄值?为什么?文档在哪里?
非常感谢!David
Clerk,CHIFOOJobs
chifoo.org
BasePage.html 是:
<html>
<head>
<title>Base Page</title>
</head>
<body>
</body>
</html>
解决方案
推荐阅读
- android - json地图样式解析在android中失败
- node.js - Node.js 中的 Cookie 转换
- flutter - 颤振中的 notifyListeners 不起作用,即该值根本没有更新
- regex - SED:替换多个文件的部分
- c# - JsonConvert 类,它是与列表的继承
- java - 字符串索引超出范围,将字符串数组转换为字符数组
- javascript - ESLint 显示错误并建议使用 try...catch
- android - 如何使用 SavedStateHandle 作为参数正确创建应用程序 ViewModel
- html - 营业时间表
- mapbox - 从 Mapbox GL JS 矢量源获取/列出源层