List of usage examples for org.openqa.selenium WebDriver findElement
@Override WebElement findElement(By by);
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Check according to the link text.// w w w . ja v a 2s.co m * @param driver the driver * @param fieldname the fieldname * @param timeOut the time out * @return boolean */ public static boolean isDisplayedByLinkText(final WebDriver driver, final String fieldname, final int timeOut) { boolean isLoaded = false; isLoaded = (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { WebElement element = driver.findElement(By.linkText(fieldname)); return element.isDisplayed(); } }); return isLoaded; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Retrieve Element according to the Text provided. * @param driver the driver/*from w w w.j a v a2 s .c om*/ * @param fieldname the fieldname * @param timeOut the time out * @return boolean */ public static WebElement retrieveElementByLinkText(final WebDriver driver, final String fieldname, final int timeOut) { isDisplayedByLinkText(driver, fieldname, timeOut); WebElement element = driver.findElement(By.linkText(fieldname)); return element; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Utility to check weather the particular field is displayed by css class name. * @param driver the driver//from w w w.j a v a 2 s .c om * @param fieldname the fieldname * @param textValue the text value * @param textValue2 the text value2 * @param timeOut the time out * @return boolean */ public static boolean isDisplayedByClassNameForWeeklySchedule(final WebDriver driver, final String fieldname, final String textValue, final String textValue2, final int timeOut) { boolean isLoaded = false; isLoaded = (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { boolean outcome = false; WebDriverWait wait = new WebDriverWait(driver, timeOut); wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className(fieldname))); WebElement element = d.findElement(By.className(fieldname)); if (element.getText().contains(textValue) || element.getText().contains(textValue2)) { outcome = true; } return outcome; } }); return isLoaded; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Clear and input.//from w ww .j a va 2s . c o m * @param driver the driver * @param locator the locator * @param fieldValue the field value */ public static void clearAndInput(final WebDriver driver, final By locator, final String fieldValue) { final WebElement element = driver.findElement(locator); element.clear(); element.sendKeys(fieldValue); }
From source file:com.elastica.webelements.HtmlElement.java
License:Apache License
/** * Wait element to present using Explicit Waits with timeout in seconds. This method is used for special element * which needs long time to present./*from w w w . ja va 2 s . c om*/ */ public void waitForPresent(final int timeout) { TestLogging.logWebStep(null, "wait for " + this.toString() + " to present.", false); Wait<WebDriver> wait = new WebDriverWait(driver, timeout); wait.until(new ExpectedCondition<WebElement>() { public WebElement apply(final WebDriver driver) { return driver.findElement(by); } }); }
From source file:com.etouch.cisco.common.CiscoMainPage.java
public void SignIn(TestParameters input) throws InterruptedException { final int MAX_WAIT = 20; try {/*from ww w. ja va 2 s .c o m*/ if ((TestBedManager.INSTANCE.getCurrentTestBed().getDeviceName() == null) || TestBedManager.INSTANCE.getCurrentTestBed().getDeviceName().isEmpty()) { ((TextBox) webPage.findObject(ObjectType.TextBox, MainPageElements.UName_ID, ObjectValType.ID)) .enterText(input.getParamMap().get("uname")); ((TextBox) webPage.findObject(ObjectType.TextBox, MainPageElements.PWD_ID, ObjectValType.ID, MAX_WAIT, WaitCondition.VISIBLE)).enterText(input.getParamMap().get("pwd")); ((Button) webPage.findObject(ObjectType.Button, MainPageElements.Login_BTN_ID, ObjectValType.ID, MAX_WAIT, WaitCondition.CLICKABLE)).click(); } else if (TestBedManager.INSTANCE.getCurrentTestBed().getDeviceName().equalsIgnoreCase("Android")) { WebDriver driver = (WebDriver) TestBedManager.INSTANCE.getCurrentTestBed().getDriver(); driver.findElement(By.id(MainPageElements.UName_ID)).sendKeys(input.getParamMap().get("uname")); driver.findElement(By.id(MainPageElements.PWD_ID)).sendKeys(input.getParamMap().get("pwd")); driver.findElement(By.id(MainPageElements.Login_BTN_ID)).click(); } ////////webPage.sleep(100); } catch (Exception e) { log.error(getErrMessage()); System.out.println("Error: " + getErrMessage()); } }
From source file:com.evolveum.midpoint.selenium.BaseTest.java
License:Apache License
protected void performLogin(WebDriver driver, String username, String password) { driver.get(siteUrl + "/login"); driver.findElement(By.id("userName")).sendKeys(username); driver.findElement(By.id("userPass")).sendKeys(password); driver.findElement(By.cssSelector("input.button")).click(); }
From source file:com.evolveum.midpoint.selenium.BaseTest.java
License:Apache License
protected void performLogout(WebDriver driver) { WebElement logout = driver.findElement(By.xpath("//div[@id=\"login-box\"]/a[1]")); if (logout == null) { fail("Couldn't find logout link."); }//from www. j a v a 2s .co m logout.click(); }
From source file:com.example.selenium.Table.java
public boolean validateTable() { boolean flag = true; List<WebElement> tablesRows; try {// w ww .j a va 2s. c om Select selectRows = new Select(tableDropDown); tableDropDown.click(); Thread.sleep(2000); selectRows.selectByValue("10"); tableDropDown.click(); WebDriverWait wait = new WebDriverWait(selenium, 10); tablesRows = wait.until(ExpectedConditions .numberOfElementsToBe(By.xpath("//table[@id='dataTables-example']/tbody/tr"), 10)); if (tablesRows.size() != 10) { flag = false; } Thread.sleep(1000); selectRows.selectByValue("25"); tableDropDown.click(); tablesRows = wait.until(ExpectedConditions .numberOfElementsToBe(By.xpath("//table[@id='dataTables-example']/tbody/tr"), 25)); if (tablesRows.size() != 25) { flag = false; } Thread.sleep(1000); selectRows.selectByValue("50"); tableDropDown.click(); tablesRows = wait.until(ExpectedConditions .numberOfElementsToBe(By.xpath("//table[@id='dataTables-example']/tbody/tr"), 50)); if (tablesRows.size() != 50) { flag = false; } Thread.sleep(2000); tableSearch.sendKeys("Presto"); Thread.sleep(1000); WebElement element = new WebDriverWait(selenium, 5).until(new ExpectedCondition<WebElement>() { public WebElement apply(WebDriver d) { return d.findElement(By.xpath("//td[contains(text(),'Presto')]")); } }); if (!element.getText().equals("Presto")) { flag = false; } return flag; } catch (InterruptedException ex) { Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex); } return flag; }
From source file:com.firewallid.crawling.FacebookApp.java
private WebDriver createWebDriver() { WebDriver webdriver = new HtmlUnitDriver(BrowserVersion.BEST_SUPPORTED, true); webdriver.get(FACEBOOK_URL);/*w w w. j a v a2s. co m*/ webdriver.findElement(By.id(conf.get(EMAIL_FIELD_ID))).sendKeys(conf.get(EMAIL)); webdriver.findElement(By.id(conf.get(PASSWORD_FIELD_ID))).sendKeys(conf.get(PASSWORD)); webdriver.findElement(By.id(conf.get(LOGIN_BUTTON_ID))).click(); return webdriver; }