List of usage examples for org.openqa.selenium WebDriver manage
Options manage();
From source file:applango.common.services.Applango.genericApplangoWebsiteActions.java
public static void clickOnLogin(WebDriver driver) throws IOException { SeleniumTestBase.logger.info("Clicking on login button (by id)"); driver.findElement(By.id(applangoButtons.LOGIN_SUBMIT.getValue())).click(); System.currentTimeMillis();//from w w w. ja va 2 s .c o m driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); }
From source file:base.GalenTestBase.java
@Override public WebDriver createDriver(Object[] args) { WebDriver driver = new FirefoxDriver(); if (args.length > 0) { if (args[0] != null && args[0] instanceof TestDevice) { TestDevice device = (TestDevice) args[0]; if (device.getScreenSize() != null) { driver.manage().window().setSize(device.getScreenSize()); }/*from w ww . j a v a 2 s. c o m*/ } } return driver; }
From source file:bg.pragmatic.lecture13mvn.waits.utils.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. * //from w w w. j a v a 2 s . co m * @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) */ 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:bg.pragmatic.lecture13mvn.waits.utils.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.//from w w w .ja v a2s . c o m * * @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) */ 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:bg.pragmatic.lecture13mvn.waits.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 w w . j a va 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:bg.pragmatic.lecture13mvn.waits.utils.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. * /*from ww w . j a v a2s . c o m*/ * 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 */ 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>() { 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:bg.pragmatic.lecture13mvn.waits.utils.WaitTool.java
License:Open Source License
/** * Wait for the Text to be present in the given element, regardless of being * displayed or not./*from w w w . j a va 2 s . c o m*/ * * @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 */ 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>() { 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:bg.pragmatic.lecture13mvn.waits.utils.WaitTool.java
License:Open Source License
/** * Waits for the Condition of JavaScript. * // w ww .ja va 2 s . c o m * * @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 * * @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>() { 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:bg.pragmatic.lecture13mvn.waits.utils.WaitTool.java
License:Open Source License
/** * Waits for the completion of Ajax jQuery processing by checking * "return jQuery.active == 0" condition. * /*from w w w. j ava2s . c o m*/ * @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 * * @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>() { 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; }
From source file:bg.pragmatic.lecture13mvn.waits.utils.WaitTool.java
License:Open Source License
/** * Coming to implicit wait, If you have set it once then you would have to * explicitly set it to zero to nullify it - *//*w w w. j a v a2s . c o m*/ public static void nullifyImplicitWait(WebDriver driver) { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify // implicitlyWait() }