Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在selenium/python中的新选项卡中打开特定链接_Python 3.x_Selenium_Selenium Webdriver - Fatal编程技术网

Python 3.x 如何在selenium/python中的新选项卡中打开特定链接

Python 3.x 如何在selenium/python中的新选项卡中打开特定链接,python-3.x,selenium,selenium-webdriver,Python 3.x,Selenium,Selenium Webdriver,我试图在新选项卡中打开一个链接,该特定链接出现在网页中。我在网上看到的所有示例似乎都是直接用代码发送链接,然后在新选项卡中打开链接,而不是动态获取链接 Changerequest是我希望在新选项卡中打开并在执行某些功能后关闭新选项卡的链接 Sourcecontrol = driver.find_element_by_xpath('//li[@class="menu-item"]/a[contains(.,"Source Control")]') Sourcecontrol.click();

我试图在新选项卡中打开一个链接,该特定链接出现在网页中。我在网上看到的所有示例似乎都是直接用代码发送链接,然后在新选项卡中打开链接,而不是动态获取链接

Changerequest是我希望在新选项卡中打开并在执行某些功能后关闭新选项卡的链接

Sourcecontrol = driver.find_element_by_xpath('//li[@class="menu-item"]/a[contains(.,"Source Control")]')
   Sourcecontrol.click();
   Changerequest=driver.find_element_by_xpath( '//td[@class="confluenceTd"]/a[contains(.,"Change: ")]').send_keys(Keys.CONTROL + 't');
   #testvalue = Changerequest.get_attribute('href')
   driver.execute_script("window.open(Changerequest)")
当我使用快捷键时,似乎什么都没有发生

send_keys(Keys.CONTROL + 't')
这是解决办法

Sourcecontrol = driver.find_element_by_xpath('//li[@class="menu-item"]/a[contains(.,"Source Control")]')
Sourcecontrol.click();
Changerequest=driver.find_element_by_xpath( '//td[@class="confluenceTd"]/a[contains(.,"Change: ")]')
testvalue = Changerequest.get_attribute('href')
driver.execute_script("window.open(arguments[0])",testvalue)

CTRL+T会打开一个新的空白选项卡,但不会在该选项卡中打开特定的URL。您可以打开新选项卡,然后设置所需的URL。您可以尝试按住SHIFT键并单击链接,因为我认为这在某些浏览器中可能会起作用,但我自己没有尝试过,这可能取决于浏览器。