简体   繁体   English

使用 Selenium WebDriver 的新标签

[英]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 网站上,但这对我来说非常有效

  • Update selenium to its alpha version using 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.

相关问题 如何通过将Selenium WebDriver与Java一起在同一浏览器中打开新标签页? - How to open a new tab in the same browser by using Selenium WebDriver with Java? 如何使用 Selenium WebDriver 在新标签页(chrome)中打开链接? - How to open a link in new tab (chrome) using Selenium WebDriver? 在Selenium Webdriver中使用Ctrl +单击组合打开新选项卡 - Opening a new tab using Ctrl + click combination in Selenium Webdriver 如何在 Java 中使用 Selenium WebDriver 打开一个新选项卡? - How to open a new tab using Selenium WebDriver in Java? 如何使用Selenium Webdriver打开新的Chrome标签页? - How to open a new chrome tab using selenium webdriver? 如何单击新标签中的打开链接以使用 selenium webdriver 在主标签中显示的新标签中打开链接 - How to click on open link in new tab to open the link in new tab that appears in main tab using selenium webdriver Selenium Webdriver新选项卡URL未正确加载 - Selenium webdriver new tab URL is not loaded properly 无法使用Selenium Webdriver切换选项卡 - Unable to do switch the tab using Selenium webdriver 使用Selenium WebDriver在页面中查找选项卡 - Finding a tab within a page using selenium webdriver 使用Selenium Webdriver在文本区域中键入TAB - Type TAB in text area using Selenium Webdriver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM