by
0
5
1,604
0
Top 1% !
Famous
Tagged
Specified
OpenSource
Popularity: 13701st place
Created
Modified Feb 18, 2017
Languagejava
LicenseMIT_X11

This method will return WebElement After Given wait

Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1671726/This-method-will-return-WebElement-After?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// This method will return WebElement After Given wait public static WebElement FindWithWait(WebDriver driver,By locator, int seconds) throws Exception{ // Sleep until the Element we want is visible or n seconds is over WebElement element=null; //Because if implict wait is set then fluint wait will not work driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); try{ FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver) .withTimeout(seconds, TimeUnit.SECONDS) .pollingEvery(200, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class) .ignoring(StaleElementReferenceException.class) .ignoring(WebDriverException.class); element=fluentWait.until( ExpectedConditions.visibilityOfElementLocated(locator) ); return element; } catch(Exception e){ throw new Exception("Timeout reached when searching for element! Time: " + seconds+" seconds " +"\n" +e.getMessage()); } finally { driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus