List of usage examples for org.openqa.selenium By partialLinkText
public static By partialLinkText(String partialLinkText)
From source file:com.sugarcrm.candybean.automation.element.Hook.java
License:Open Source License
/** * A helper method to convert Hook to By * @param hook The hook that specifies a web element * @return The converted By//from w ww . java 2s . c o m * @throws CandybeanException */ public static By getBy(Hook hook) throws CandybeanException { switch (hook.hookStrategy) { case CSS: return By.cssSelector(hook.hookString); case XPATH: return By.xpath(hook.hookString); case ID: return By.id(hook.hookString); case NAME: return By.name(hook.hookString); case LINK: return By.linkText(hook.hookString); case PLINK: return By.partialLinkText(hook.hookString); case CLASS: return By.className(hook.hookString); case TAG: return By.tagName(hook.hookString); default: throw new CandybeanException("Strategy type not recognized."); } }
From source file:com.sugarcrm.candybean.automation.webdriver.WebDriverElement.java
License:Open Source License
public static By By(Strategy strategy, String hookString) throws CandybeanException { switch (strategy) { case CSS: return By.cssSelector(hookString); case XPATH://from w w w. ja va 2 s . com return By.xpath(hookString); case ID: return By.id(hookString); case NAME: return By.name(hookString); case LINK: return By.linkText(hookString); case PLINK: return By.partialLinkText(hookString); case CLASS: return By.className(hookString); case TAG: return By.tagName(hookString); default: throw new CandybeanException("Strategy type not recognized."); } }
From source file:com.surevine.alfresco.space.webdriver.SiteDashBoard.java
License:Open Source License
public DocumentLibraryPage navigateToDocumentLibrary() { // The number of spaces in the Document library link appear to be confusing the driver, so use partialLinkText API instead. WebElement docLibraryLink = driver.findElement(By.partialLinkText("Document Library")); docLibraryLink.click();// w w w . ja v a2 s. com return new DocumentLibraryPage(driver); }
From source file:com.testmax.handler.SeleniumBaseHandler.java
License:CDDL license
protected HashMap<String, By> getByFromAttribute() { HashMap<String, By> bys = new HashMap<String, By>(); String[] attrlist = this.havingAttribute.split("#"); for (String attrelm : attrlist) { By by = null;// w ww . j a v a2 s . c o m if (attrelm.split("::")[0].equals("id") && attrelm.split("::").length > 1) { by = By.id(attrelm.split("::")[1]); this.printMessage("****LOCATED attribute id=" + attrelm.split("::")[1] + " for tag with havingAttribute=" + this.havingAttribute); //return by; bys.put("id", by); } else if (attrelm.split("::")[0].equals("name")) { by = By.name(attrelm.split("::")[1]); this.printMessage("****LOCATED attribute name=" + attrelm.split("::")[1] + " for tag with havingAttribute=" + this.havingAttribute); //return by; bys.put("name", by); } else if (attrelm.split("::")[0].equals("class")) { by = By.className(attrelm.split("::")[1]); this.printMessage("****LOCATED attribute class=" + attrelm.split("::")[1] + " for tag with havingAttribute=" + this.havingAttribute); //return by; bys.put("class", by); } else if (this.tagName.equals("a") && attrelm.split("::")[0].equals("text")) { by = By.linkText(attrelm.split("::")[1]); this.printMessage("****LOCATED attribute text=" + attrelm.split("::")[1] + " for tag with havingAttribute=" + this.havingAttribute); bys.put("text", by); //return by; } else if (this.tagName.equals("a") && attrelm.split("::")[0].equals("text")) { by = By.partialLinkText(attrelm.split("::")[1]); this.printMessage("****LOCATED attribute text=" + attrelm.split("::")[1] + " for tag with havingAttribute=" + this.havingAttribute); //return by; bys.put("a", by); } else if (attrelm.split("::")[0].equals("xpath")) { String xpath = attrelm.split("::")[1]; xpath = xpath.replaceAll("!", "'"); by = By.xpath(xpath); this.printMessage("****LOCATED attribute xpath=" + attrelm.split("::")[1] + " for tag with havingAttribute=" + this.havingAttribute); //return by; bys.put("xpath", by); } else if (attrelm.split("::")[0].equals("css")) { by = By.cssSelector(attrelm.split("::")[1]); this.printMessage("****LOCATED attribute css=" + attrelm.split("::")[1] + " for tag with havingAttribute=" + this.havingAttribute); bys.put("css", by); //return by; } } if (this.tagName.contains(".")) { By by = By.cssSelector(this.tagName); bys.put("css", by); this.printMessage( "****LOCATED attribute cssSelector=" + this.tagName + " for tag with tagname=" + this.tagName); } else if (!this.isEmptyValue(id)) { By by = By.id(this.id); bys.put("id", by); } return bys; }
From source file:com.ts.commons.TSPageFactory.TSAnnotations.java
License:Apache License
protected By buildByFromLongFindBy(FindBy findBy) { How how = findBy.how();//ww w . j a va 2 s . c om String using = findBy.using(); switch (how) { case CLASS_NAME: return (By) By.className(using); case CSS: return (By) By.cssSelector(using); case ID: return (By) By.id(using); case ID_OR_NAME: return (By) ((org.openqa.selenium.By) new ByIdOrName(using)); case LINK_TEXT: return (By) By.linkText(using); case NAME: return (By) By.name(using); case PARTIAL_LINK_TEXT: return (By) By.partialLinkText(using); case TAG_NAME: return (By) By.tagName(using); case XPATH: return (By) By.xpath(using); default: // Note that this shouldn't happen (eg, the above matches all // possible values for the How enum) throw new IllegalArgumentException("Cannot determine how to locate element " + field); } }
From source file:com.ts.commons.TSPageFactory.TSAnnotations.java
License:Apache License
protected By buildByFromShortFindBy(FindBy findBy) { if (!"".equals(findBy.className())) return (By) By.className(findBy.className()); if (!"".equals(findBy.css())) return (By) By.cssSelector(findBy.css()); if (!"".equals(findBy.id())) return (By) By.id(findBy.id()); if (!"".equals(findBy.linkText())) return (By) By.linkText(findBy.linkText()); if (!"".equals(findBy.name())) return (By) By.name(findBy.name()); if (!"".equals(findBy.partialLinkText())) return (By) By.partialLinkText(findBy.partialLinkText()); if (!"".equals(findBy.tagName())) return (By) By.tagName(findBy.tagName()); if (!"".equals(findBy.xpath())) return (By) By.xpath(findBy.xpath()); // Fall through return null;//from ww w. j a v a 2s .com }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Object locator./*from w ww .j a v a 2 s . c om*/ * * @param objectID * the object id * @return the web element * @throws Exception * the exception */ public final WebElement objectLocator(final String objectID) throws Exception { Logger log = getLog(); log.info("INFO : Finding Element [ " + objectID + " ]"); WebDriver driver = getDriver(); String typeString = ""; String ref = ""; String objectIDinLowerCase = objectID.toLowerCase(Locale.getDefault()); boolean isObjectTypeisXpath = objectIDinLowerCase.startsWith("/"); if (!isObjectTypeisXpath) { typeString = objectIDinLowerCase.substring(0, objectIDinLowerCase.indexOf('=')); ref = objectID.substring(objectID.indexOf('=') + 1, objectID.length()); } if (isObjectTypeisXpath) { return driver.findElement(By.xpath(objectID)); } else if ("xpath".equals(typeString)) { return driver.findElement(By.xpath(ref)); } else if ("css".equals(typeString)) { return driver.findElement(By.cssSelector(ref)); } else if ("id".equals(typeString)) { return driver.findElement(By.id(ref)); } else if ("link".equals(typeString)) { return driver.findElement(By.partialLinkText(ref)); } else if ("tagname".equals(typeString)) { return driver.findElement(By.tagName(ref)); } else if ("classname".equals(typeString) || "class".equals(typeString)) { return driver.findElement(By.className(ref)); } else if ("name".equals(typeString)) { return driver.findElement(By.name(ref)); } log.error("Invalid Locator Type Passed " + objectID + ". Expected locator types : XPATH, CSS, ID, NAME, LINK, TAGNAME, CLASSNAME"); throw new Exception("Invalid Locator Type Passed " + ref); }
From source file:contentspeed.CreareContNou.java
void ClickRegister() { driver.findElement(linkRegister).click(); String MainWindow = driver.getWindowHandle(); System.out.println(MainWindow); driver.switchTo().window(MainWindow); driver.findElement(By.partialLinkText("Finalizeaza comanda")).click(); driver.switchTo().defaultContent();//w w w . j ava 2 s . c om }
From source file:contentspeed.ProdusCeai.java
public void clickFinalizeaza() { try {/*from w w w.java 2 s . c o m*/ String MainWindow = driver.getWindowHandle(); System.out.println(MainWindow); driver.switchTo().window(MainWindow); driver.findElement(By.partialLinkText("Finalizeaza comanda")).click(); driver.switchTo().defaultContent(); } catch (WebDriverException ex) { System.out.println("Exceptie"); //ex.printStackTrace(); //driver.quit(); } }
From source file:contentspeed.ProdusCeai.java
void closeCookie() { String textDIV = driver.findElement(cookieDIV).getText(); String cookie = driver.getWindowHandle(); driver.switchTo().window(cookie);/*from www .jav a 2 s.c o m*/ driver.findElement(By.partialLinkText("Sunt de acord")).click(); /*System.out.println(textDIV); */ driver.switchTo().defaultContent(); }