Note that there are some explanatory texts on larger screens.

plurals
  1. POWebDriver FluentWait - can the Function/Predicate throw an Exception?
    primarykey
    data
    text
    <p>I'm extending Selenium's <code>By</code> class into a broader <code>Locator</code> class that can accept different types of location criteria and that will provide new methods to our version of <code>SearchContext</code> and/or <code>WebDriver</code>.</p> <p>I have the following method which waits for a unique element to exist, be displayed, and be enabled:</p> <pre><code>public void waitForElementPresent(BSWebDriver driver, int timeoutSeconds) { try { FluentWait&lt;BSWebDriver&gt; wait = new FluentWait&lt;BSWebDriver&gt;(driver) .withTimeout(timeoutSeconds, TimeUnit.SECONDS) .pollingEvery(5, TimeUnit.SECONDS) .ignoring(NoSuchElementException.class); wait.until(new Function&lt;BSWebDriver, Boolean&gt;() { public Boolean apply(BSWebDriver driver) { return isElementPresent(driver); } }); } catch (TimeoutException timeoutEx) { throw new WaitForElementException(this, timeoutSeconds, WAIT_FOR.PRESENT); } } </code></pre> <p><code>isElementPresent</code> is a method which handles the check for whether the element is present (i.e. that it exists, is displayed, and is enabled), but without waiting. The problem is that <code>isElementPresent</code> throws a custom error <code>Exception</code> if the locator does not uniquely identify an element (that is, if more than one element is returned which matches the location criteria). There is currently a compile error in the above code since, as far as I can tell, neither <code>Function</code> nor <code>Predicate</code> are allowed to throw an <code>Exception</code>, and there aren't any subclasses that can either.</p> <p>Is there any way to do this? Is there some form of <code>Function</code> or <code>Predicate</code> that <em>can</em> throw an Exception, like Java's <code>Callable</code> vs. <code>Runnable</code>? If there isn't, I guess I may just have to write my own version of the wait functionality. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload