[英]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.