1

I click a button which opens a new tab. How to I then navigate around the new tab?

This sounds like a simple task but after several hours trying to find a solution I'm not any closer. Is there a simple way of doing this?

Tried using keys for CONTROL + 'T' and read other suggestions but nothing seems to work.

Many thanks

blountdj
  • 599
  • 1
  • 11
  • 23

1 Answers1

5

I just implemented my solution and it worked for my case, which looks very similar to yours.

First you need to check the window_handles:

len(driver.window_handles) > 1

If you have more than one, you can try to switch to your second handler:

driver.switch_to_window(driver.window_handles[1])
boechat107
  • 1,654
  • 14
  • 24
  • Did not work on Chrome with the latest selenium and chrome driver – DollarAkshay Jan 06 '17 at 19:07
  • 1
    @AkshayLAradhya, does `driver.window_handles` a length greater than one? Have you tried to inspect its content? – boechat107 Jan 06 '17 at 19:54
  • Yes It had a length greater than 1, I printed it out onto the console. I gave up on chrome tabs, using firefox now. – DollarAkshay Jan 06 '17 at 20:18
  • Hum, weird, I was able to use it on Chrome some time ago. Anyway, [here](http://selenium-python.readthedocs.io/navigating.html#moving-between-windows-and-frames) is the piece of documentation I used. – boechat107 Jan 07 '17 at 14:14
  • Akshay, you have to wait for the second tab to show in the list. You have to use sleep for better results – red777 Jul 30 '18 at 14:36