Send keys control + click in Selenium with Python bindings
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need to open link in new tab using Selenium. So is it possible to perform ctrl+click on element in Selenium to open it in new tab? 回答1: Use an ActionChain with key_down to press the control key, and key_up to release it: import time from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys driver = webdriver.Chrome() driver.get('http://google.com') element = driver.find_element_by_link_text('About') ActionChains(driver) \ .key_down(Keys.CONTROL) \ .click