简体   繁体   English

在Python中使用Selenium WebDriver在新标签页/窗口中打开链接

[英]Using Selenium WebDriver in Python to Open Link in New Tab/Window

I'm having an issue in Selenium where I want to open a link in a new tab. 我在Selenium中遇到问题,我想在新标签页中打开链接。 It doesn't have an href either, so obtaining the url as a string doesn't seem possible. 它也没有href,因此似乎不可能以字符串形式获取url。

I have tried to use ActionChains from Selenium , but I can't get it to work. 我尝试使用Selenium的 ActionChains ,但是无法正常使用。

actions = ActionChains(self.driver) 
actions.key_down(Keys.COMMAND)
actions.move_to_element(element)
actions.click()
actions.key_up(Keys.COMMAND)
actions.perform()

This code ends up doing nothing as far as I can tell. 据我所知,这段代码最终无济于事。

if webdriver click is not working, you could use javascript to click on an element which opens a new tab/window. 如果webdriver click不起作用,则可以使用javascript单击打开新标签页/窗口的元素。

def click_using_javascript():
    browser.execute_script('arguments[0].click();', element) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Control + Click of Selenium Webdriver 在同一窗口的新选项卡中的主选项卡中打开嵌入在 webelement 中的链接 - How to open a link embeded in a webelement with in the main tab, in a new tab of the same window using Control + Click of Selenium Webdriver Python - 使用 Selenium WebDriver 在新的 Chrome 选项卡中打开链接? - Python - Open a link in new Chrome tab with Selenium WebDriver? Python + Selenium WebDriver:在新标签页中打开URL - Python + Selenium WebDriver: open URL in new tab 如何使用python的Selenium WebDriver在浏览器上打开一个新的window? - How to open a new window on a browser using Selenium WebDriver for python? 使用selenium和python在现有标签页/窗口中打开新页面中的链接 - Open a link in a new page opening in the existing tab/window using selenium and python 如何在webdriver(Python)中打开一个新窗口或选项卡? - How to open a new window or tab in webdriver (Python)? 如何使用python和selenium在新选项卡中打开链接 - How to open a link in a new tab with python and selenium python selenium 在新标签页中打开链接并继续 session 在新标签页中 - python selenium open link in new tab and continue session in new tab Selenium webdriver在python中的chrome编码中打开一个新选项卡 - Selenium webdriver open a new tab in chrome coding in python 在Mac上使用Selenium WebDriver在Firefox中打开新标签页 - Open new tab in Firefox using Selenium WebDriver on Mac
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM