2

I need to open a separate window from a link in my main page and leave the main opened. I am using the following code to do so:

self.find_element_by_locator(locator="css==a[href='#/vehicles']").send_keys(Keys.CONTROL + Keys.RETURN)

Then I need to do some stuff in the new window, so I try to switch the focus to it:

windows = self.driver.window_handles
driver.switch_to.window(windows[1])

Problem: - The window opens correctly but the focus remains on the main window. (in this case, the Error is that the index is out of range) When I make a Breakpoint and look into the windows I see there is only one element in the list, which refers to the main page and the new page doesn't appear. I also tried opening a new Tab (sending keys Control 't' and then sending keys CONTROL TAB) but the problem remains (The window handles only sees one page or tab)

There is a similar Question but even the implicit_wait doesn't help.

I saw many people having the same problem, but still can't find an answer. Do I have to create a completely other WebDriver or is there easier ways to resolve this problem?

I'm working on Windows10 64Bit / Selenium 3.4.3 / Python 3 and IE11 (IEDriverServer_x64_3.4.0)

4
  • What about other browsers, does the exact same test pass in other browsers - Chrome, Firefox? – alecxe Jul 31 '17 at 16:31
  • I can't really say. I need it to run on IE since it's required by the project. – Anas Bouayed Jul 31 '17 at 16:32
  • I am just trying to isolate the issue..trying to see if it is browser-specific. – alecxe Jul 31 '17 at 16:36
  • Was there any progress with this? I am also sometimes experiencing this. Selenium+Java on IE11 and Chrome. Is it a Selenium issue? Intermittently failing to switch to a new tab or window. – Mate Mrše Apr 23 '19 at 9:49
1

In my case, before switch to the new window, a simply thread sleep make thing done.

time.sleep(3)

# switch to new window

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.