0

To verify the correctness, I started to press the keys after clicking on the input to see whether they are being clicked.

elem = driver.find_element_by_id("q")
elem.send_keys('t')
ActionChains(driver).key_down(Keys.LEFT_SHIFT).send_keys('ff').perform()

The code above will enter into the input tFF, that is, the left shift is clamped. But you should rewrite it to CTRL + t:

elem = driver.find_element_by_id("q")
elem.send_keys('t')
ActionChains(driver).key_down(Keys.LEFT_CONTROL).send_keys('t').perform()

And it does not work, even though it should be logical.

Sergey Kirillov
  • 29
  • 1
  • 2
  • 5
  • element.send_keys(Keys.COMMAND, 't') – santhosh kumar Jun 23 '17 at 13:07
  • control + t will open the new tab in browser. Do you want to open new tap? – Murthi Jun 23 '17 at 13:21
  • See [Open web in new tab Selenium + Python](https://stackoverflow.com/questions/28431765/open-web-in-new-tab-selenium-python). [a comment](https://stackoverflow.com/questions/28431765/open-web-in-new-tab-selenium-python#comment91110223_28432939) explains why the solution doesn't work – user202729 Aug 18 '21 at 03:42

3 Answers3

1

To open a new empty tab

driver.execute_script('''window.open("","_blank");''')

To open a url in new tab(say https://www.google.com)

driver.execute_script('''window.open("https://www.google.com","_blank");''')
Rajarajan
  • 21
  • 2
0

Can you try with following,

elem = driver.find_element_by_id("q")
elem.send_keys('t')
ActionChains(driver).key_down(Keys.LEFT_CONTROL).send_keys('t').key_up(Keys.LEFT_CONTROL).perform()
Murthi
  • 5,299
  • 1
  • 10
  • 15
0

Pressing the CTRL+ T opens a new tab in Windows machine and even in Mac Machine, no keys are entered in the text box by pressing CTRL+T

If you want to try the other option for sending keys in the text box. It can be:

ActionChains(driver).key_down(Keys.SHIFT).send_keys('t').key_up(Keys.SHIFT).perform()
Delgan
  • 18,571
  • 11
  • 90
  • 141
Monika
  • 714
  • 1
  • 4
  • 10
  • I need to open a new tab. When input is active, a new tab can be opened using the CTRL + T. You can check it out. – Sergey Kirillov Jun 24 '17 at 17:58
  • I think you are looking for this answer. Please follow the link: https://stackoverflow.com/questions/17547473/how-to-open-a-new-tab-using-selenium-webdriver-with-java – Monika Jun 25 '17 at 06:20