0

I cannot open a new tab using Firefox WebDriver. I've found a lot of suggestions, e.g. here, here, and here, but they do not work. E.g. none of these worked:

ActionChains(driver)\
    .move_to_element(driver.find_element_by_tag_name("body"))\
    .key_down(Keys.CONTROL)\
    .key_down("t")\
    .key_up(Keys.CONTROL) \
    .key_up("t") \
    .perform()

or

driver.find_element_by_tag_name("body").send_keys(Keys.CONTROL + "t")

Only this works:

driver.execute_script("window.open()")
driver.switch_to.window(driver.window_handles[1])

Can anyone present a better working solution without a need to use JavaScript features?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
ibodi
  • 1,543
  • 3
  • 21
  • 40
  • What's wrong with JavaScript? – Andersson Aug 16 '18 at 14:06
  • @Andersson, I am just wondering what I am doing wrong. And it seems that there must be more obvious solution. – ibodi Aug 16 '18 at 14:26
  • 2
    IMHO, `execute_script("window.open()")` is most obvious and efficient solution – Andersson Aug 16 '18 at 14:32
  • https://stackoverflow.com/questions/17547473/how-to-open-a-new-tab-using-selenium-webdriver-with-java scroll through the comments, there are multiple different solutions there (even thought they are in Java, easily converted for your case). from what I see there people are talking about window focus that is needed so send_keys will work. – Shlomi Bazel Aug 21 '18 at 23:15
  • 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 ctrl+T doesn't work. There isn't any option – user202729 Aug 18 '21 at 03:28

0 Answers0