[英]New Tab using Selenium WebDriver
How do I open a new tab using Selenium
WebDriver all the other answers I found were out of date and/or inaccurate.如何使用
Selenium
WebDriver 打开一个新选项卡我发现的所有其他答案都已过时和/或不准确。
I've tried:我试过了:
body = driver.find_element_by_tag_name("body")
body.send_keys(Keys.CONTROL + 't')
but this does not work reliably and needs manual switching to the new tab that's unreliable但这并不可靠,需要手动切换到不可靠的新标签
You could use your send_keys method to open a new tab, and I believe Selenium also offers a function to switch tabs.您可以使用您的 send_keys 方法打开一个新选项卡,我相信 Selenium 还提供了一个 function 来切换选项卡。
Yeah so Finally I found a foolproof solution to this problem the solution is actually there in the official Selenium website but this worked perfectly for me是的,所以最后我找到了解决这个问题的万无一失的解决方案,该解决方案实际上在官方 Selenium 网站上,但这对我来说非常有效
pip install selenium==4.0.0.a7
pip install selenium==4.0.0.a7
将 selenium 更新到其 alpha 版本Link to downloads page on official selenium website链接到官方 selenium 网站上的下载页面
Yeah and then you can create a new tab using this command:是的,然后您可以使用以下命令创建一个新选项卡:
Link to Selenium Documentation on it's offical website 链接到其官方网站上的 Selenium 文档
# Opens a new tab and switches to new tab
driver.switch_to.new_window('tab')
# Opens a new window and switches to new window
driver.switch_to.new_window('window')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.