Org.openqa.selenium.ElementNotVisibleException: the item is not currently visible and therefore cannot interact with

I am trying to execute the Selenium Web script driver below, but I get an error org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted withseveral times (not all the time). sometimes in cycles the first iteration, and sometimes in 2 iterations, and sometimes without an initial cycle. It correctly prints all available elements, but the serum tries to click on the elements, showingElement is not currently visible...

public void pickitems() throws Exception  
        {
        Webdriver driver = new firefoxdriver();
        driver.get("http://www.bigbasket.com");
        driver.manage().window().maximize();
            //Selecting Location
        List<WebElement> list = driver.findElement(By.id("ftv-city-popup")).findElements(By.tagName("button"));
        int location = r.nextInt(list.size());
        list.get(location).click();
            //Selection random Category from left panel through list 
        Thread.sleep(30000);
        List<WebElement> xyz = driver.findElement(By.id("uiv2-main-menu")).findElements(By.className("top-category"));
        System.out.println(xyz.size());
        Random r = new Random();
        int category = r.nextInt(xyz.size());
        xyz.get(category).click();


        for (int i = 0; i < 3; i++) {
            Thread.sleep(30000);
            List<WebElement> availableItems = driver.findElements(By.cssSelector("a.uiv2-add-button.a2c"));
            System.out.println(availableItems.size());
            if (availableItems.size() > 0)
            {
                int selectItem = r.nextInt(availableItems.size());
                availableItems.get(selectItem).click();

            } 
            else
            {
                Thread.sleep(30000);
                List<WebElement> availableItems2 = driver.findElements(By.cssSelector("a.uiv2-add-button.a2c"));
                if (availableItems2.size() == 0) {
                    System.out.println("No more items are available. Sorry for the inconvenience");
                }
                else {
                    Assert.fail("Unable to select items. May be page loading issue");
                }


            }

        }

  }

}
+4
source share
5 answers

Finally, it worked for me. The item is currently not visible and therefore cannot interact with.

, 2 5 . , , .

IE. ActiveX. IFRAMES. , , , . presenceOfElementLocated visibilityOfElementLocated , .

    WebDriverWait wait = new WebDriverWait(driver,30);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='campaignListTable']")));   /*examining the xpath for a search     
    box*/
    driver.findElement(By.xpath("//*[@id='campaignListTable']")).sendKeys("TEXT");   /*enter text in search 
    box*/
+6

, . , , .

  • Selenium , , .
  • , , .

, ,

 new WebDriverWait(Driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementIsVisible("your selector"); 
+6

, , "ElementNotVisibleException", , . "a.uiv2-add-button.a2c" ? , "ElementNotVisibleException"

0

, , , Selenium . perform() , , Selenium .

WebElement xWL = driver.findElement(By.xpath("x path text"));

Actions xAct = new Actions(driver);

:

xAct.moveToElement(xWL).build().perform();

,

xAct.moveToElement(xWL);
xAct.click();
xAct.perform();
0

.

Thread.sleep(5000);
WebElement zoneName=driver.findElement(By.xpath("//*[@id=\"zoneName\"]"));
zoneName.sendKeys("kandy");
-1

All Articles