List of usage examples for org.openqa.selenium WebDriver manage
Options manage();
From source file:bg.pragmatic.lecture13mvn.waits.utils.WaitTool.java
License:Open Source License
/** * Reset ImplicitWait. To reset ImplicitWait time you would have to * explicitly set it to zero to nullify it before setting it with a new time * value./*ww w. ja v a2 s. co m*/ */ public static void resetImplicitWait(WebDriver driver) { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify // implicitlyWait() driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset // implicitlyWait }
From source file:bg.pragmatic.lecture13mvn.waits.utils.WaitTool.java
License:Open Source License
/** * Reset ImplicitWait./* w w w. j av a 2s .co m*/ * * @param int - a new wait time in seconds */ public static void resetImplicitWait(WebDriver driver, int newWaittime_InSeconds) { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify // implicitlyWait() driver.manage().timeouts().implicitlyWait(newWaittime_InSeconds, TimeUnit.SECONDS); // reset // implicitlyWait }
From source file:bg.pragmatic.myautomationframework.utils.WaitTool.java
License:Open Source License
/** * Wait for the List<WebElement> to be present in the DOM, regardless of * being displayed or not. Returns all elements within the current page DOM. * /*from w ww. jav a 2 s . c om*/ * @param WebDriver * The driver object to be used * @param By * selector to find the element * @param int The time in seconds to wait until returning a failure * * @return List<WebElement> all elements within the current page DOM, or * null (if the timeout is reached) */ public static List<WebElement> waitForListElementsPresent(WebDriver driver, final By by, int timeOutInSeconds) { List<WebElement> elements; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify // implicitlyWait() WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driverObject) { return areElementsPresent(driverObject, by); } }); elements = driver.findElements(by); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset // implicitlyWait return elements; // return the element } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:br.com.mundotigre.scripts.WaitTool.java
License:Open Source License
/** * Wait for the element to be present in the DOM, and displayed on the page. * And returns the first WebElement using the given method. * * @param WebDriver The driver object to be used * @param By selector to find the element * @param int The time in seconds to wait until returning a failure * * @return WebElement the first WebElement using the given method, or null (if the timeout is reached) *//*from w w w . j a va 2s. c o m*/ public static WebElement waitForElement(WebDriver driver, final By by, int timeOutInSeconds) { WebElement element; try { //To use WebDriverWait(), we would have to nullify implicitlyWait(). //Because implicitlyWait time also set "driver.findElement()" wait time. //info from: https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/6VO_7IXylgY driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); element = wait.until(ExpectedConditions.visibilityOfElementLocated(by)); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait return element; //return the element } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:br.com.mundotigre.scripts.WaitTool.java
License:Open Source License
/** * Wait for the element to be present in the DOM, regardless of being displayed or not. * And returns the first WebElement using the given method. * * @param WebDriver The driver object to be used * @param By selector to find the element * @param int The time in seconds to wait until returning a failure * * @return WebElement the first WebElement using the given method, or null (if the timeout is reached) *///from w ww.j a va2s. co m public static WebElement waitForElementPresent(WebDriver driver, final By by, int timeOutInSeconds) { WebElement element; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); element = wait.until(ExpectedConditions.presenceOfElementLocated(by)); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait return element; //return the element } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:br.com.mundotigre.scripts.WaitTool.java
License:Open Source License
/** * Wait for the List<WebElement> to be present in the DOM, regardless of being displayed or not. * Returns all elements within the current page DOM. * * @param WebDriver The driver object to be used * @param By selector to find the element * @param int The time in seconds to wait until returning a failure * * @return List<WebElement> all elements within the current page DOM, or null (if the timeout is reached) *//*from ww w.j a v a2 s .c o m*/ public static List<WebElement> waitForListElementsPresent(WebDriver driver, final By by, int timeOutInSeconds) { List<WebElement> elements; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); wait.until((new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driverObject) { return areElementsPresent(driverObject, by); } })); elements = driver.findElements(by); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait return elements; //return the element } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:br.com.mundotigre.scripts.WaitTool.java
License:Open Source License
/** * Wait for an element to appear on the refreshed web-page. * And returns the first WebElement using the given method. * * This method is to deal with dynamic pages. * * Some sites I (Mark) have tested have required a page refresh to add additional elements to the DOM. * Generally you (Chon) wouldn't need to do this in a typical AJAX scenario. * * @param WebDriver The driver object to use to perform this element search * @param locator selector to find the element * @param int The time in seconds to wait until returning a failure * * @return WebElement the first WebElement using the given method, or null(if the timeout is reached) * * @author Mark Collin //w ww.j ava 2 s.c o m */ public static WebElement waitForElementRefresh(WebDriver driver, final By by, int timeOutInSeconds) { WebElement element; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() new WebDriverWait(driver, timeOutInSeconds) { }.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driverObject) { driverObject.navigate().refresh(); //refresh the page **************** return isElementPresentAndDisplay(driverObject, by); } }); element = driver.findElement(by); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait return element; //return the element } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:br.com.mundotigre.scripts.WaitTool.java
License:Open Source License
/** * Wait for the Text to be present in the given element, regardless of being displayed or not. * * @param WebDriver The driver object to be used to wait and find the element * @param locator selector of the given element, which should contain the text * @param String The text we are looking * @param int The time in seconds to wait until returning a failure * * @return boolean // w w w .j a v a2 s. co m */ public static boolean waitForTextPresent(WebDriver driver, final By by, final String text, int timeOutInSeconds) { boolean isPresent = false; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() new WebDriverWait(driver, timeOutInSeconds) { }.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driverObject) { return isTextPresent(driverObject, by, text); //is the Text in the DOM } }); isPresent = isTextPresent(driver, by, text); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait return isPresent; } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:br.com.mundotigre.scripts.WaitTool.java
License:Open Source License
/** * Waits for the Condition of JavaScript. * * * @param WebDriver The driver object to be used to wait and find the element * @param String The javaScript condition we are waiting. e.g. "return (xmlhttp.readyState >= 2 && xmlhttp.status == 200)" * @param int The time in seconds to wait until returning a failure * /*from w w w .j a v a2 s . co m*/ * @return boolean true or false(condition fail, or if the timeout is reached) **/ public static boolean waitForJavaScriptCondition(WebDriver driver, final String javaScript, int timeOutInSeconds) { boolean jscondition = false; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() new WebDriverWait(driver, timeOutInSeconds) { }.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driverObject) { return (Boolean) ((JavascriptExecutor) driverObject).executeScript(javaScript); } }); jscondition = (Boolean) ((JavascriptExecutor) driver).executeScript(javaScript); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait return jscondition; } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:br.com.mundotigre.scripts.WaitTool.java
License:Open Source License
/** Waits for the completion of Ajax jQuery processing by checking "return jQuery.active == 0" condition. * * @param WebDriver - The driver object to be used to wait and find the element * @param int - The time in seconds to wait until returning a failure * /*w w w .j a v a 2s .c o m*/ * @return boolean true or false(condition fail, or if the timeout is reached) * */ public static boolean waitForJQueryProcessing(WebDriver driver, int timeOutInSeconds) { boolean jQcondition = false; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() new WebDriverWait(driver, timeOutInSeconds) { }.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driverObject) { return (Boolean) ((JavascriptExecutor) driverObject).executeScript("return jQuery.active == 0"); } }); jQcondition = (Boolean) ((JavascriptExecutor) driver).executeScript("return jQuery.active == 0"); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait return jQcondition; } catch (Exception e) { e.printStackTrace(); } return jQcondition; }