最新消息:20210917 已从crifan.com换到crifan.org

【已解决】Selenium如何跳转到新打开的tab页窗口

selenium crifan 7631浏览 0评论

折腾:

【记录】尝试用Python操作PhantomJS+Selenium去模拟购物操作

期间,在点击了一个按钮之后,新打开一个tab页:

selenium如何跳转过去,继续处理页面?

selenium jump to new tab

Python Selenium – Open new tab / focus tab / close tab

How to switch to another Tab using Selenium WebDriver with Java – Stack Overflow

driver.getWindowHandles

Switch between browser tabs using Selenium WebDriver with Java – Stack Overflow

How can I take a browser’s control to a newly opened tab using Java in WebDriver – Stack Overflow

selenium  window tab

Switch between two open windows or browser tabs | LogicAndTricks

automated testing – switching between tabs in a browser – Software Quality Assurance & Testing Stack Exchange

通过PyCharm的自动匹配完成,可以看到,有很多window handle相关的内容:

进去看看源码:

<code>@property
</code>

通过调试可以看到,当前有两个window:

且当前的window是在window_handles的列表中的第一个

所以可以去切换去第二个tab了:

但是看到

switch_to_window中有个删除线:

估计是被废弃了。

点击去看源码,果然是:

<code>def switch_to_window(self, window_name):
</code>

所以换成:

<code>allWindowHandles = driver.window_handles
</code>

看看效果

是可以切换到新的tab的:

【总结】

此处用:

<code>allWindowHandles = driver.window_handles
</code>

去实现了,跳转到新的tab。

其中switch_to_window已废弃,已换成switch_to.window

转载请注明:在路上 » 【已解决】Selenium如何跳转到新打开的tab页窗口

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
93 queries in 0.185 seconds, using 23.35MB memory