After clicking a button it redirect to another webpage associated with it. when i write code to select object in that page i am not able select field

Viewed 26

After clicking a button it redirect to another webpage associated with it. when i write code to select object in the new page i am not able select field in the new page

WebElement next23 = driver.findElement(By.xpath("//span[contains(text(),'Search Units')]")); next23.click(); // this redirect to new page then no code is working on the new page

1 Answers

After clicking the element opening a new tab you need to switch the driver to that tab. Selenium will not do it automatically.
This can be done with the following code:

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

After that you will be able to continue on the new tab with your test flow.

Related