0

I have an issue with Selenium. I have a scenario:

  1. Users opens a browser via script:

    driver = webdriver.Firefox()
    driver.get ("some_startpage")
    
  2. Then USER opens a new tab (the person clicks, it is done not by selenium, but manually).

I want to change one element on page in second tab, but my webdriver is focused on the first tab.

I've tried with driver.getWindowHandles() to change webdriver focus, but it shows me only one handle (to the main window), and I cannot switch context to the second tab.

  • webdriver.tittle shows the title of the second tab and
  • webdriver.current_url shows the url of the first tab

But thats normall. I've read that selenium doesn't support tabs in browser.

My questions:

  • Is there any work around (mayby js?) to operate on elements on second (third, fourth...) tab in browser?
  • I don't want to open new browser window, and human must manually open tab, it can't be done via selenium.
Aleksei Zyrianov
  • 2,294
  • 1
  • 24
  • 32
  • Do you want to open a new tab with your code? – Kasisnu Jul 27 '14 at 10:30
  • No Kasisnu, user personally opens a new tab. I want to integrate with elements(for example via js) in new tab. But my selenium driver is focused on the different tab (that is opened via webdriver). – Tomek Ratagnar Jul 27 '14 at 20:34
  • You're very likely to be out of luck. If the user were to open a new instance of the browser manually, would you expect the driver to be able to drive it (hint: the answer is "no")? Now consider that a new manually opened tab is indistinguishable from a new browser instance from WebDriver's perspective. This, I would expect the driver to be unable to recognize a manually opened tab. – JimEvans Jul 28 '14 at 02:18
  • http://stackoverflow.com/questions/6421988/webdriver-open-new-tab Maybe you could try something like this. – Kasisnu Jul 28 '14 at 03:00
  • @JimEvans but if there is a way to get the new tab handle for example exploring(enumerating) the opened windows in operating systems and send that handle to driver.switchTo().window(winHandle). – Tomek Ratagnar Jul 28 '14 at 07:32
  • Do not confuse the overloaded term "window handle" here. The "handle" used by WebDriver is **not** the Windows (or other operating system) window handle. Rather, it is simply a unique string the driver assigns to the window for purposes of identification. If WebDriver doesn't recognize the tab, it won't have a "handle" to use with `switchTo().window()`. – JimEvans Jul 28 '14 at 08:58

0 Answers0