Python 使用window.open()获取另一个页面的html元素

Python 使用window.open()获取另一个页面的html元素,python,firefox,selenium-webdriver,Python,Firefox,Selenium Webdriver,我正在尝试从使用window.open()访问的html页面访问html元素 这些是我的htmls: firstpage.html: <html> <body> <script> function openPage() { return window.open("secondpage.html") } </script> </body> </html> <html> <body> <scr

我正在尝试从使用window.open()访问的html页面访问html元素

这些是我的htmls:

firstpage.html:

<html>
<body>
<script>
function openPage() {
  return window.open("secondpage.html")
}
</script>
</body>
</html>
<html>
<body>
<script>
function openPage() {
  window.open("secondpage.html", "secondpagewindow")
}
</script>
</body>
</html>
我希望得到的是对第二页文档元素的引用。这似乎在Firefox web控制台中起作用。当我测试脚本时,第二页打开,但第一页似乎挂起,过了一会儿,我看到一个对话框说:

此页上的脚本可能正忙,或已停止响应。您可以立即停止脚本,也可以继续查看脚本是否将完成

使用“停止”和“继续”按钮。按“Continue”对话框将继续显示,当我最终按“Stop”时,html python变量包含对话框的相同文本

我做错了什么

编辑: 正如@e1che的答案一样,这是正确的方法:

firstpage.html:

<html>
<body>
<script>
function openPage() {
  return window.open("secondpage.html")
}
</script>
</body>
</html>
<html>
<body>
<script>
function openPage() {
  window.open("secondpage.html", "secondpagewindow")
}
</script>
</body>
</html>
你做得很好

但是你没能把你的司机换到新的车窗

因此,在进入
浏览器之后,立即执行脚本(“return openPage().document;”

你写了这样的东西:

driver.switch_to_window("windowName")
我让你搜索;)

driver.switch_to_window("windowName")