List of usage examples for org.openqa.selenium By name
public static By name(String name)
From source file:com.qkn.automation.pages.LoginPage.java
public void navigateToSignup() throws Exception { WebDriverWait wait = new WebDriverWait(pageDriver, 120); wait.until(ExpectedConditions//from www . j a v a 2 s . c o m .visibilityOfElementLocated(By.name(pageprops.getProperty("SINGUP_BUTTON_LOGINPAGE")))); pageDriver.findElement(By.name(pageprops.getProperty("SINGUP_BUTTON_LOGINPAGE"))).click(); }
From source file:com.qmetry.qaf.automation.ui.selenium.AssertionService.java
License:Open Source License
public String takeScreenShot() { try {/*from w w w . ja va 2s. c o m*/ lastCapturedScreenShot = captureScreenShot_remote(); return lastCapturedScreenShot; } catch (Throwable th) { if ((th.getMessage() != null) && (th.getMessage().indexOf("WebDriver") >= 0)) { String base64Image = ""; try { if (th.getCause() instanceof ScreenshotException) { throw th; } WebDriver driver = ((QAFWebDriverBackedSelenium) selenium).getWrappedDriver(); driver.findElement(By.name("current screen shot")).sendKeys("capture"); logger.info("Unable to capture ScreenShot: " + th.getMessage()); return ""; } catch (Throwable t) { Throwable cause = t.getCause(); if (cause instanceof ScreenshotException) { base64Image = ((ScreenshotException) cause).getBase64EncodedScreenshot(); lastCapturedScreenShot = base64ImageToFile(base64Image); return lastCapturedScreenShot; } else { System.out.println("Unable to retrive capture ScreenShot: " + t.getMessage()); } } } else { try { lastCapturedScreenShot = captureScreenShot(); return lastCapturedScreenShot; } catch (Throwable t) { logger.info("Unable to capture ScreenShot: " + th.getMessage() + "\n" + t.getMessage()); } } } return ""; }
From source file:com.qmetry.qaf.automation.util.LocatorUtil.java
License:Open Source License
public static By getBy(String loc, PropertyUtil props) { Gson gson = new Gson(); loc = props.getSubstitutor().replace(loc); loc = props.getString(loc, loc);//w w w. ja v a 2 s . co m JsonElement element = JSONUtil.getGsonElement(loc); if ((null != element) && element.isJsonObject()) { Object obj = gson.fromJson(element, Map.class).get("locator"); loc = obj instanceof String ? (String) obj : gson.toJson(obj); } element = JSONUtil.getGsonElement(loc); if ((null != element) && element.isJsonArray()) { String[] locs = new Gson().fromJson(element, String[].class); return new ByAny(locs); } if (loc.startsWith("//")) { return By.xpath(loc); } else if (loc.indexOf("=") > 0) { String parts[] = loc.split("=", 2); if (parts[0].equalsIgnoreCase("key") || parts[0].equalsIgnoreCase("property")) { String val = props.getSubstitutor().replace(parts[1]); return getBy(props.getString(val, val), props); } if (parts[0].equalsIgnoreCase("jquery")) { return new ByJQuery(parts[1]); } if (parts[0].equalsIgnoreCase("name")) { return By.name(parts[1]); } else if (parts[0].equalsIgnoreCase("id")) { return By.id(parts[1]); } else if (parts[0].equalsIgnoreCase("xpath")) { return By.xpath(parts[1]); } else if (parts[0].equalsIgnoreCase("css")) { return By.cssSelector(parts[1]); } else if (parts[0].equalsIgnoreCase("link") || parts[0].equalsIgnoreCase("linkText")) { return By.linkText(parts[1]); } else if (parts[0].equalsIgnoreCase("partialLink") || parts[0].equalsIgnoreCase("partialLinkText")) { return By.partialLinkText(parts[1]); } else if (parts[0].equalsIgnoreCase("className")) { return By.className(parts[1]); } else if (parts[0].equalsIgnoreCase("tagName")) { return By.tagName(parts[1]); } else { return new ByCustom(parts[0], parts[1]); } } else { return By.xpath(String.format("//*[@name='%s' or @id='%s' or @value='%s']", loc, loc, loc)); } }
From source file:com.raja.anucarita.SeCustomUtils.java
License:Open Source License
public static WebElement elementReturn(WebDriver driver, String locator) throws Exception { byMethod = locator.split("=", 2)[0]; actualLocator = locator.split("=", 2)[1]; if (byMethod.equalsIgnoreCase("css")) { element = driver.findElement(By.cssSelector(actualLocator)); } else if (byMethod.equalsIgnoreCase("jQuery")) { final String LocatorTwo = actualLocator; String Timeout = values.getProperty("timeout"); try {//from w w w . ja v a 2s . co m wait = new WebDriverWait(driver, Integer.parseInt(Timeout)); wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driver) { Result = false; try { element = findElementByjQuery(driver, LocatorTwo); if (element instanceof WebElement) { Result = true; } else { Result = false; } } catch (Exception e) { } return Result; } }); } catch (Exception e) { } element = findElementByjQuery(driver, actualLocator); } else if (byMethod.equalsIgnoreCase("linkText")) { element = driver.findElement(By.linkText(actualLocator)); } else if (byMethod.equalsIgnoreCase("id")) { element = driver.findElement(By.id(actualLocator)); } else if (byMethod.equalsIgnoreCase("name")) { element = driver.findElement(By.name(actualLocator)); } else if (byMethod.equalsIgnoreCase("ByIDorName")) { driver.findElement(new ByIdOrName(actualLocator)); } else if (byMethod.equalsIgnoreCase("partialLinkText")) { element = driver.findElement(By.partialLinkText(actualLocator)); } else if (byMethod.equalsIgnoreCase("xpath")) { element = driver.findElement(By.xpath(actualLocator)); } else { } if (element instanceof WebElement) { return element; } else { element = null; } return null; }
From source file:com.raja.anucarita.SeCustomUtils.java
License:Open Source License
public static List<WebElement> elementsReturn(WebDriver driver, String locator) throws Exception { byMethod = locator.split("=", 2)[0]; actualLocator = locator.split("=", 2)[1]; if (byMethod.equalsIgnoreCase("css")) { elements = driver.findElements(By.cssSelector(actualLocator)); } else if (byMethod.equalsIgnoreCase("jQuery")) { /*/* ww w.j a va 2s . c o m*/ Need to write code for iterating multiple elements with jQuery */ String Timeout = values.getProperty("timeout"); final String LocatorTwo = actualLocator; try { wait = new WebDriverWait(driver, Integer.parseInt(Timeout)); wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driver) { Result = false; try { element = findElementByjQuery(driver, LocatorTwo); if (element instanceof WebElement) { Result = true; } else { Result = false; } } catch (Exception e) { } return Result; } }); } catch (Exception e) { } element = findElementByjQuery(driver, actualLocator); elements.add(element); /**/ } else if (byMethod.equalsIgnoreCase("linkText")) { elements = driver.findElements(By.linkText(actualLocator)); } else if (byMethod.equalsIgnoreCase("id")) { elements = driver.findElements(By.id(actualLocator)); } else if (byMethod.equalsIgnoreCase("name")) { elements = driver.findElements(By.name(actualLocator)); } else if (byMethod.equalsIgnoreCase("ByIDorName")) { driver.findElements(new ByIdOrName(actualLocator)); } else if (byMethod.equalsIgnoreCase("partialLinkText")) { elements = driver.findElements(By.partialLinkText(actualLocator)); } else if (byMethod.equalsIgnoreCase("xpath")) { elements = driver.findElements(By.xpath(actualLocator)); } else { } return elements; }
From source file:com.rakhi.selenium.endtoend.EndToEndTest.java
@Test public void testNpuNewAccount() throws Exception { driver.get(baseUrl);//from ww w.java 2s . co m driver.findElement(By.id("lst-ib")).clear(); driver.findElement(By.id("lst-ib")).sendKeys("NPU"); driver.findElement(By.name("btnG")).click(); driver.findElement(By.linkText("Northwestern Polytechnic University - Fremont")).click(); Thread.sleep(2000); driver.findElement(By.linkText("Admissions")).click(); Thread.sleep(2000); driver.findElement(By.linkText("Application Guide")).click(); Thread.sleep(2000); driver.navigate().back(); Thread.sleep(2000); driver.findElement(By.linkText("Graduate")).click(); Thread.sleep(2000); driver.navigate().back(); Thread.sleep(1000); driver.navigate().back(); Thread.sleep(1000); driver.findElement(By.linkText("Academics")).click(); Thread.sleep(2000); driver.findElement(By.linkText("School of Engineering")).click(); Thread.sleep(2000); driver.navigate().back(); Thread.sleep(2000); driver.findElement(By.linkText("Scholarships")).click(); Thread.sleep(2000); driver.navigate().back(); Thread.sleep(1000); driver.navigate().back(); Thread.sleep(1000); driver.findElement(By.linkText("Campus")).click(); Thread.sleep(2000); driver.findElement(By.linkText("Club Facilities")).click(); Thread.sleep(2000); driver.navigate().back(); Thread.sleep(2000); driver.findElement(By.linkText("Career Center")).click(); Thread.sleep(2000); driver.navigate().back(); Thread.sleep(1000); driver.navigate().back(); Thread.sleep(1000); driver.findElement(By.linkText("NPU News")).click(); Thread.sleep(2000); driver.findElement(By.linkText("Student Association Blog")).click(); Thread.sleep(2000); driver.navigate().back(); Thread.sleep(2000); driver.findElement(By.linkText("NPU Globe")).click(); Thread.sleep(2000); driver.navigate().back(); Thread.sleep(1000); driver.navigate().back(); Thread.sleep(1000); driver.findElement(By.linkText("Apply Online")).click(); Thread.sleep(2000); driver.findElement(By.id("regcheck")).click(); Thread.sleep(2000); driver.findElement(By.linkText("Register Account")).click(); Thread.sleep(2000); driver.navigate().back(); Thread.sleep(1000); driver.navigate().back(); Thread.sleep(1000); driver.quit(); }
From source file:com.redhat.darcy.webdriver.internal.DefaultWebDriverElementContext.java
License:Open Source License
@Override public <T> List<T> findAllByName(Class<T> type, String name) { return newElementList(type, new WebElementListLookup(By.name(name), sc)); }
From source file:com.redhat.darcy.webdriver.internal.DefaultWebDriverElementContext.java
License:Open Source License
@Override public <T> T findByName(Class<T> type, String name) { return newElement(type, new WebElementLookup(By.name(name), sc)); }
From source file:com.redhat.darcy.webdriver.internal.WebElementContext.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/* w w w.j av a 2s.com*/ public <T> List<T> findAllByName(Class<T> type, String name) { return (List<T>) By.name(name).findElements(sc); }
From source file:com.redhat.darcy.webdriver.internal.WebElementContext.java
License:Open Source License
@SuppressWarnings("unchecked") @Override public <T> T findByName(Class<T> type, String name) { return (T) By.name(name).findElement(sc); }