ElementNotVisibleException: Element is not currently visible | Selenium Forum
M
Posted on 24/01/2016
ElementNotVisibleException, How to fix this? have i used wrong xpath for Add_buttons contents?
or cache is clearing up & i reassign Add_buttons just before line code[triggers ElementNotVisibleException: Element is not currently visible]..>have already tried that,dint resolve the issue?

This is my code:
===============================================
package p1;

import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;
import org.testng.annotations.BeforeTest;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterTest;

public class shopping_veggies {
static Xls_Reader xls = new Xls_Reader("C:\\Users\\chaitra\\Pictures\\bigBasket.xlsx");
static int rNum;
static WebDriver w;
static List <WebElement>Products;
static List <WebElement>Product_ids;
static List <WebElement>Add_buttons;
static WebElement fruitveggy;
static Actions A;
static WebElement Box;

@Test(dataProvider = "dp")
public void f(String Products_xls, String Quantity_xls) {

System.out.println("**********rounds start****************");

for(int i=0;i<Products.size();i++)
{

if(Products.get(i).getAttribute("title").matches(Products_xls))
{
//System.out.println("clase1");
if(Add_buttons.get(i).isEnabled())
{
System.out.println("clase");
Add_buttons.get(i).click();
//System.out.println("got clicked"+i+"this"+Products_xls);
//break;
}


}

}


}

@DataProvider
public Object[][] dp() {

int rows = xls.getRowCount("Basket");
int cols = xls.getColumnCount("Basket");

Object data[][] = new Object[rows-1][cols];

for(rNum=2;rNum<=rows;rNum++){
for(int cNum=0;cNum<cols;cNum++){
//System.out.println(xls.getCellData("Basket", cNum, rNum));
data[rNum-2][cNum] = xls.getCellData("Basket", cNum, rNum);

// 2 0 [0][0]
// 2 1 [0][1]
// 3 0 [1][0]
// 3 1 [1][1]
}
};

return data;
}
@BeforeTest
public void beforeTest() {
ProfilesIni prof = new ProfilesIni();
FirefoxProfile p = prof.getProfile("Chaitra");
w=new FirefoxDriver(p);
//w.get("http://bigbasket.com/");need update
w.get("http://www.bigbasket.com/pc/fruits-vegetables/fresh-herbs-seasonings/chilli-lemon-garlic-ginger/?nc=nb");
w.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
Box=w.findElement(By.xpath("html/body/div[19]/div[5]/div[2]"));
Product_ids=w.findElements(By.xpath("//li[starts-with(@id,'product_')]"));
Products=Box.findElements(By.xpath("//*[@class='uiv2-our-recommendations-list-box']/li/div/a"));


Add_buttons=new ArrayList<WebElement>();
Add_buttons=Box.findElements(By.xpath("//*[@class='uiv2-add-to-basket']/a"));
//Add_buttons=Box.findElements(By.xpath("//a[starts-with(@id, 'p_10000')]"));
System.out.println("size"+Add_buttons.size());
//a[starts-with(@id, 'p_10000')]
}

}

M
Replied on 24/01/2016

pls suggest sir.
Have attached all related files.


M
Replied on 24/01/2016

sir,
tried explicit wait , does not seem to work...

what more solutions can i try ?

============================
try{
Ab=Add_buttons.get(i);
//wait.until(ExpectedConditions.visibilityOf(Ab));
//wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@class='uiv2-add-to-basket']/a")));
//wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='p_10000117']")));
//wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id='p_10000117")));

//wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@class='uiv2-add-to-basket']/a")));
//wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='p_10000117']")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id='p_10000117")));

Add_buttons.get(i).click();
}catch(Exception e)
{
e.printStackTrace();
System.out.println("ther'z an exception");
}


M
Replied on 25/01/2016

[quote:2hg6atl3]wait.until(ExpectedConditions.visibilityOfElementLocated(By.id([color=#FF0000:2hg6atl3]"id='p_10000117"[/color:2hg6atl3])));[/quote:2hg6atl3]

id is wrong.

use this
[color=#FF0000:2hg6atl3]
(By.id("p_10000117"))[/color:2hg6atl3]


M
Replied on 26/01/2016

Sir,

there r 5 Add buttons on the page.
with following ids:
//*[@id='p_10000117_1']-->ADD button for product1
//*[@id='p_10000081_1']-->ADD button for product2
//*[@id='p_10000126_1']-->ADD button for product3
//*[@id='p_10000114_1']-->ADD button for product4
//*[@id='p_10000079_1']-->ADD button for product5

Now, by my code ,//*[@id='p_10000117_1']-->ADD button for product1; //*[@id='p_10000079_1']-->ADD button for product5
buttons get successfully clicked.

But others do not get clicked:
i used wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("p_10000081_1")));
jus before Add_buttons.get(i).click();

This still gives me same issue.3 ADD buttons are not clicked.