简体   繁体   中英

How to press browser shortcuts keys with python selenium

I am trying to use browsers shortcut with pyhton selenium but I can't get any shortcut to work.

For example, I am trying to open a new tab ( Control + T ) using ActionChains() . I tried the following two but nothing seems to change:

ActionChains(driver).key_down(Keys.CONTROL).send_keys('T').key_up(Keys.CONTROL).perform()

and

element = driver.find_element_by_tag_name('html')
element.click()
ActionChains(driver).key_down(Keys.CONTROL).send_keys('T').key_up(Keys.CONTROL).perform()

What is the proper way to use shortcuts in python selenium?

Browser shortcuts seem to be unreliable with Selenium. I would open a new tab with javascript:

driver.execute_script("window.open()")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM