2

The automation task involves the use of Chrome Keyboard shortcuts like Ctrl+t, Ctrl+Tab using Selenium driver with Python.

I have used multiple methods that have been defined for using keyboard shortcuts

driver.find_element_by_tag_name('html').send_keys(Keys.CONTROL + 't')
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')

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

ActionChains(driver).key_down(Keys.CONTROL).key_down('t').key_up(Keys.CONTROL).key_up('t').perform()

But none of these seems to work. I have tried this on Chrome, Firefox and Opera. Have used Chromedriver, Geckodriver and Operadriver for the three browsers.

Has anyone been able to successfully implement shortcut keys using selenium webdriver and python?

To be more explicit, I want to cycle through the open tabs on Chrome using the "Ctrl+t" shortcut. I do not want to access tabs using the switch_to_window method

Roshan Santhosh
  • 677
  • 3
  • 9
  • Possible duplicate of [How to send keyboard shortcut ALT SHIFT z (hotkey) with Selenium2?](https://stackoverflow.com/questions/11520341/how-to-send-keyboard-shortcut-alt-shift-z-hotkey-with-selenium2) – BcK May 15 '18 at 13:21
  • Update the question with your exact _usecase_ – undetected Selenium May 15 '18 at 14:47

1 Answers1

0

You can try below code :-

driver.find_element_by_css_selector('body').send_keys(Keys.CONTROL + 't')
Ankur Singh
  • 1,239
  • 1
  • 8
  • 18