首页 > 解决方案 > 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>

标签: seleniumselenium-webdriverselenium-firefoxdriver

解决方案


推荐阅读