Ak17
Ak17

Reputation: 85

Element not visible exception with firefox webdriver

I have identified a weblement through xpath and below is the same for that from the given HTML code

XPath expression

//a[@id='close_bttn']

Document

<form action="/gateway/orders" method="get">
<input class="dynamic-table-search-by" type="hidden" value="Date Range" name="searchBy"/>

<input type="hidden" value="20" name="pageSize"/>
<div class="input-prepend input-append">

<a id="close_bttn" class="btn dynamic-table-search-clear" href="/gateway/orders?pageSize=20&totalItems=16024" type="button">
<i class="icon-remove dynamic-table-search-clear-icon"/>
</a>

After the WebDriver run, I am seeing the error as

Element is not currently visible and so may not be interacted with Command duration or timeout.

I see that there is no hidden tag added for the XPath i'm working on. Please let me know if there is any work around for this issue.

Upvotes: 0

Views: 674

Answers (2)

djangofan
djangofan

Reputation: 29669

Here is how I might do it, using a double-check, just to make sure:

   public boolean isElementThere( By locator ) { 
      boolean found = false;
      WebDriverWait waiting = new WebDriverWait(driver, 30, 2500);
      WebElement element;
      try {
        element = waiting.until(
            ExpectedConditions.visibilityOfElementLocated(locator));
        element = waiting.until(
            ExpectedConditions.presenceOfElementLocated(locator));
      } catch ( WebDriverException e ) {
         return false;
      }
      if ( element != null ) found = true;
      return found;
   }

Upvotes: 0

Gyorgy.Hegedus
Gyorgy.Hegedus

Reputation: 361

I guess you should use WebDriveWait :

WebDriverWait waiting = new WebDriverWait(driver, X, Y);

WebElement element = waiting.until(ExpectedConditions.visibilityOfElementLocated(By.id("close_bttn")));

This code will check the expected condition (visibility of the close_bttn object) in every Y milliseconds. The wait time is X seconds.

Upvotes: 1

Related Questions