简体   繁体   中英

I am facing ElementNotVisible issue while clicking on image poster

I am facing ElementNotVisible issue while clicking on image poster in image section with next and back arrow (< >). Image posters are changing in some time interval like on image is right now child but after some time period same becomes parent or hide and other becomes chick. It changes dynamically.

Below is the code:

while(!isFound)
{
    Thread.sleep(7500);
    driver.findElement(By.xpath("(//a[contains(text(),'Prev')])[2]")).click();////Clicking on Back/Prevous arrow

    if(driver.findElement(By.xpath("(//a[@id='carousel-item-3025']/img)[2]")).isDisplayed())
    {
        driver.findElement(By.xpath("(//a[@id='carousel-item-3025']/img)[2]")).isFound=true;
        break;
    }

Please provide the solution.

You should wait until required element becomes visible:

WebDriverWait wait= new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@id='carousel-item-3025']/img)[2]"))).click();

Note that this code should wait not more than 10 seconds for element to become visible. If full cycle of images rotation is more than 10 seconds you should set more time to wait

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM