Naveen Chettigari
Naveen Chettigari

Reputation: 57

Switching between tabs using webdriver in chrome

Am Opening a page performing some actions on that and i am using this piece of code to open another link in the next tab

String url = "https://qa.logfireapps.com/lgf_700_qa_rf";

String args1 = String.format("window.open('%s', '%s');", url, "new");

((JavascriptExecutor) driver).executeScript(args1);

Then i need to switch between this two tabs.

I used driver.switchTo.window(parentWin);

I also used this code

List windowHandles1 = new ArrayList(driver.getWindowHandles()); driver.switchTo().window(windowHandles1.get(1));

Both of the cases did not work for me,but still the web driver code is running successfully without any errors even its not switching to first window.

I need to switch to the first tab,but all the actions are going on in the first tab but still in UI am seeing the second tab opened,It is not switching to the first tab but my whole webdriver code gets passed.

It is observed that switching problem happens only with this two sites 1) https://qa.logfireapps.com/lgf_700_qa/index/

2) https://qa.logfireapps.com/lgf_700_qa_rf

Upvotes: 0

Views: 1234

Answers (1)

Ben Dellarocco
Ben Dellarocco

Reputation: 121

This was my solution to this using python. sorry no java example

def switch_to_new_window(driver, window):
    driver.switch_to_window(driver.window_handles[window])

Upvotes: 0

Related Questions