0

After clicking a row it opens a new tab and redirects you to it , what I want is after getting redirected to it , is jump back to the original tab Original tab link is = http://localhost:82/receivechecklist.php , after clicking the row it redirects to = http://localhost:82/collection.php?wid=100000000000001

private static By clickFirstInvoice=By.xpath("//span[contains(text(),'Customer 1')]");

driver.findElement(clickFirstInvoice).click();
    Thread.sleep(500);      



new WebDriverWait(driver,10).until(ExpectedConditions.numberOfWindowsToBe(2));
    driver.switchTo().window(driver.getWindowHandles().stream().reduce((f, s) -> s).orElse(null));
    System.out.println("Successful in switching to collection tab");

I want to go back to the original tab after clicking the invoice

Bianca
  • 5
  • 2

1 Answers1

0

Before switching the tab you need to save the current window handle.

String originalTab = driver.getWindowHandle();
//perform your switch here    
driver.switchTo().window(originalTab);
AndiCover
  • 1,724
  • 3
  • 17
  • 38