0

I want to open a new tab on Selenium Firefox (on Python 3.6 and MacBook) but the command key does not work to open a new tab. For example,

driver.find_element_by_tag_name('body').send_keys(Keys.DOWN)

This works (moves a page a little down). But the following code does not work.

driver.find_element_by_tag_name('body').send_keys(Keys.COMMAND + "t")

, which should open a new tab. Another key such as "q" does not work, either.

So I'm looking for a way to open a new tab (or any other command key combinations) on Selenium and Firefox.

Is there any way except the keyboard shortcut?

Blaszard
  • 30,954
  • 51
  • 153
  • 233
  • 1
    Possible duplicate of [Open web in new tab Selenium + Python](https://stackoverflow.com/questions/28431765/open-web-in-new-tab-selenium-python) – Andersson Apr 18 '18 at 16:17
  • @Andersson I tried the way the accepted answer explains and found the command key combination is not working, though the down key is. That’s why I asked. – Blaszard Apr 18 '18 at 16:29

1 Answers1

1

To open a New Blank TAB you can use the following line of code :

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

To open a New TAB with url you can use the following line of code :

driver.execute_script("window.open('http://facebook.com/');")

Update

As per your comment update execute_script("window.open('','_blank');") should open a new TAB by default. Incase you are seeing different behavior you need to follow the below mentioned steps :

  • Upgrade Selenium to current levels Version 3.11.0.
  • Upgrade GeckoDriver to GeckoDriver v0.20.1 level.
  • Upgrade Firefox version to Firefox v59.0.1 levels.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • Use CCleaner tool to wipe off all the OS chores before and after the execution of your test Suite.
  • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your @Test.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352