1

I have started using chrome for selenium and its working fine but when I open a new tab the control goes back to the main tab and executes the script there instead of the new tab. can someone help me how to tackle this issue.

  • possible duplicate of http://stackoverflow.com/questions/12729265/switch-tabs-using-selenium-webdriver-with-java – Ranjith's Jun 29 '16 at 12:36

2 Answers2

0

try this

 ArrayList<String> tabs2 = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(tabs2.get(tabs2.size()-1));

//Then do something
selva
  • 1,175
  • 1
  • 19
  • 39
0
# Open the link in a new tab by sending key strokes on the element
# Use: Keys.CONTROL + Keys.SHIFT + Keys.RETURN to open tab on top of the stack 

url.send_keys(Keys.CONTROL + Keys.RETURN)

# Save the window opener (current window)

main_window = browser.current_window_handle

# Switch tab to the new tab

browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.TAB)

# Put focus on current window which will

browser.switch_to_window(browser.window_handles[1])

# do whatever you have to do on this page
Jatet
  • 11
  • 3