Find a WebElement on the new page using Selenium WebDriver with Java

Cleicy Guião :

I'm trying to automate a functionality where I have to open a new tab and start to work on this page, but my code still looking the WebElements on the last Tab. I try to switch the tabs with the follow code but its not working.

            public void DataManager() throws InterruptedException {
            ArrayList<String> tabs2 = new ArrayList<String> (driver.getWindowHandles());
            driver.switchTo().window(tabs2.get(0));
            driver.close();
            driver.switchTo().window(tabs2.get(1));
            WebElement tes = driver.findElement(By.xpath("//*[@id=\"lui-popover-3\"]/div/ng-transclude/ul/li[2]/button[1]/span[2]"));
            tes.click();                                
        }   

What's going on, and how can I fix this?

Cleicy Guião :

I found the solution, I had a problem to find Web Elements in my page, so when I used the following code to change the selenium focus:

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

And I searched the Web Element using press Tab I found it.

Thanks!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=110129&siteId=1