0

I'm trying a black box testing with selenium I'm working with:

  • Mac os.: version: 10.9.4
  • java.version: 1.6.0_65
  • browser: firefox version 32.0.3
  • selenium: version 2.43.0

the page holds a table, each row has a unique id which is extracted correctly and stored in String itemId Then I create the corresponding WebElement and try to click on it as follows:

WebElement anchor = webDriver.findElement(By.id(itemId));
if (anchor != null) {           
    anchor.click();
    Sleeper.sleep(2);
}

and I'm getting this exception:

WARNING: Error extracting item data
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with

I've read in couple of SO questions about WebDriverWait and tried the following code:

String itemId = item.getAttribute("id");
WebDriverWait wait = new WebDriverWait(webDriver, 10);           
WebElement anchor = wait.until(ExpectedConditions.elementToBeClickable(By.id(itemId)));
anchor.click();
Sleeper.sleep(2); // yes I know I waited 10 seconds already I have time :)

and now I get the following exception:

WARNING: Error extracting item data
org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for element to be clickable

I've tried instead of elementToBeClickable to use ElementIsVisible but it seems depricated

4
  • Not sure if I will be able to help without HTML of full page, but it is possible that you have another invisible table. You can check it by calling WebDriver.findElements(...) function and than check size of list. Commented Oct 17, 2014 at 11:44
  • @y3zier unfortunately i can't share the webpage, privacy issues, when extracting the number of tables there are 3 one that i suspect is invisible and two visible, what should I look for in order to find if a table is visible or not and what can i do? Commented Oct 17, 2014 at 11:50
  • Consider that I am not sure if this is your problem, but you can use xpath, or use a little dirty way by using List<WebElement> temp_list = driver.findElements(By.id(itemId)); and then iterate over list index by using temp_list[1].click(); (number is only example)and define if it is your item. Notice that it will work only if list have more than 1 element. You can check it by calling temp_list.size(); Commented Oct 17, 2014 at 12:03
  • @y3zier Yep you are so right!!! write it as an answer and I will accept and +1 you, thanks! Commented Oct 17, 2014 at 13:15

1 Answer 1

1

Note: This solution is not appliceable everywhere where similar error occurs, but from my experience it is common problem on web application.

If you are dealing with invisible, clone table, you can use direct xpath to visible table or use findByELements and iterate on list.

List<WebElement> temp_list = driver.findElements(By.id(itemId));
temp_list[1].click(); //example number, you have to find index corresponding to your element

notice, that it will work only when you have more than one element with same locator. You can check size of list.

temp_list.size();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.