List of usage examples for org.openqa.selenium By partialLinkText
public static By partialLinkText(String partialLinkText)
From source file:com.moodle.testmanager.pageObjectModel.Courses.java
License:GNU General Public License
/** * Clicks a course category on the course categories page from the list of available course categories. * @param courseCategory The link text of the course category. *//*from w w w . j a va 2 s.c o m*/ public void selectCourseCategory(String courseCategory) { WebElement aCourseCategory = driver.findElement(By.partialLinkText(courseCategory)); aCourseCategory.click(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); }
From source file:com.moodle.testmanager.pageObjectModel.Users.java
License:GNU General Public License
/** * Select the Logout link//w w w .j a v a 2s .c o m */ public void selectLogout() { driver.findElement(By.partialLinkText(this.properties.get("logoutLink"))).click(); }
From source file:com.moodle.testmanager.pageObjectModel.Users.java
License:GNU General Public License
/** * Logs a given user into the system. calling this method avoids repeating code. * @param uname The Username of the user you want to log into Moodle. Pass this value from the test. * @param userPassword The password of the user that you want to log into the system. Pass this value from the test. *///from w w w . ja va 2 s. c om public void loginToSystem(String uname, String userPassword) { driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); WebElement login; login = driver.findElement(By.partialLinkText(this.properties.get("loginLink"))); login.click(); WebElement username = driver.findElement(By.id("username")); username.sendKeys(uname); WebElement password = driver.findElement(By.id("password")); password.sendKeys(userPassword); driver.findElement(By.id("loginbtn")).click(); }
From source file:com.pineapple.eckotur.web.test.DeleteOffer.java
@Test public void deletecart() throws Exception { boolean success = false; driver.findElement(By.partialLinkText("delete")).click(); Thread.sleep(3000);/* w w w .jav a 2 s.c om*/ List<WebElement> rows = driver.findElements(By.xpath("//table[contains(@id,'Table')]/tbody/tr")); for (WebElement webElement : rows) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals("Colombia") && elems.get(1).getText().equals("8000000")) { List<WebElement> buttons = elems.get(2).findElements(By.xpath("button")); buttons.get(1).click(); success = true; break; } } Thread.sleep(3000); //Se busca el objeto que fue eliminado, si se encuentra hay error al eliminar rows = driver.findElements(By.xpath("//table[contains(@id,'Table')]/tbody/tr")); if (rows.size() > 0) { for (WebElement webElement : rows) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals("Viaje al centro de la tierra") && elems.get(1).getText().equals("Web ID: 1089772")) { success = false; break; } } } Thread.sleep(3000); assertTrue(success); }
From source file:com.qmetry.qaf.automation.ui.WebDriverBaseTestPage.java
License:Open Source License
public void waitForTextPresent(String text) { new QAFExtendedWebElement(By.partialLinkText(text)).waitForPresent(); }
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);//from www . 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 {// w w w. j a v a 2 s . 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 av a2s. c om 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.seleniumtests.uipage.Locator.java
License:Apache License
public static By locateByPartialLinkText(final String partialLinkText) { return By.partialLinkText(partialLinkText); }
From source file:com.sugarcrm.candybean.automation.control.VControl.java
License:Open Source License
protected static By makeBy(Strategy strategy, String hook) throws Exception { switch (strategy) { case CSS: return By.cssSelector(hook); case XPATH:/*from w ww .j av a 2 s .c om*/ return By.xpath(hook); case ID: return By.id(hook); case NAME: return By.name(hook); case LINK: return By.linkText(hook); case PLINK: return By.partialLinkText(hook); case CLASS: return By.className(hook); case TAG: return By.tagName(hook); default: throw new Exception("Selenium: strategy type not recognized."); } }