Example usage for org.openqa.selenium By xpath

List of usage examples for org.openqa.selenium By xpath

Introduction

In this page you can find the example usage for org.openqa.selenium By xpath.

Prototype

public static By xpath(String xpathExpression) 

Source Link

Usage

From source file:com.autocognite.appium.lib.base.AbstractAppiumUiDriver.java

License:Apache License

public By getFinderType(String identifier, String idValue) throws Exception {
    By findBy = null;/*  w w  w. ja va 2s  .co m*/
    MobileWebIdentifyBy idType = null;
    try {
        idType = MobileWebIdentifyBy.valueOf(identifier.toUpperCase());
    } catch (Throwable e) {
        throwUnsupportedIndentifierException(this.getName(), "getFinderType", identifier);
    }
    switch (identifier.toUpperCase()) {
    case "ID":
        findBy = By.id(idValue);
        break;
    case "NAME":
        findBy = By.name(idValue);
        break;
    case "CLASS":
        findBy = By.className(idValue);
        break;
    case "LINK_TEXT":
        findBy = By.linkText(idValue);
        break;
    case "PARTIAL_LINK_TEXT":
        findBy = By.partialLinkText(idValue);
        break;
    case "XPATH":
        findBy = By.xpath(idValue);
        break;
    case "CSS":
        findBy = By.cssSelector(idValue);
        break;
    case "TAG":
        findBy = By.tagName(idValue);
        break;
    }
    return findBy;
}

From source file:com.autocognite.appium.lib.base.AbstractAppiumUiDriver.java

License:Apache License

public MobileElement getParent(MobileElement wdElement) {
    return wdElement.findElement(By.xpath("parent::*"));
}

From source file:com.autocognite.selenium.lib.SeleniumWebUiDriver.java

License:Apache License

@SuppressWarnings("incomplete-switch")
public By getFinderType(String identifier, String idValue) throws Exception {
    By findBy = null;/*  w ww . jav a  2 s.  co  m*/
    WebIdentifyBy idType = null;
    try {
        idType = WebIdentifyBy.valueOf(identifier.toUpperCase());
    } catch (Throwable e) {
        throwUnsupportedIndentifierException(Configurator.getComponentName("WEBDRIVER_AUTOMATOR"),
                "getFinderType", identifier);
    }
    switch (idType) {
    case ID:
        findBy = By.id(idValue);
        break;
    case NAME:
        findBy = By.name(idValue);
        break;
    case CLASS:
        findBy = By.className(idValue);
        break;
    case LINK_TEXT:
        findBy = By.linkText(idValue);
        break;
    case PARTIAL_LINK_TEXT:
        findBy = By.partialLinkText(idValue);
        break;
    case XPATH:
        findBy = By.xpath(idValue);
        break;
    case CSS:
        findBy = By.cssSelector(idValue);
        break;
    case TAG:
        findBy = By.tagName(idValue);
        break;
    }
    return findBy;
}

From source file:com.autocognite.selenium.lib.SeleniumWebUiDriver.java

License:Apache License

public WebElement getParent(WebElement wdElement) {
    return wdElement.findElement(By.xpath("parent::*"));
}

From source file:com.automatewebtesting.framework.testdata.utility.SeleniumHelper.java

public WebElement findElementByXPath(String xPath) {
    return driver.findElement(By.xpath(xPath));
}

From source file:com.automationpractice.tests.AddTochart.java

public static void main(String[] args) {

    System.setProperty("webdriver.chrome.driver", "D:\\selenium test lib\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("http://automationpractice.com");

    driver.findElement(By.xpath(".//*[@id='homefeatured']/li[1]/div/div[2]/div[2]/a[1]/span")).click();
    driver.findElement(By.xpath(".//*[@id='layer_cart']/div[1]/div[2]/div[4]/a/span")).click();

    if (driver.switchTo().alert() != null) {
        Alert alert = driver.switchTo().alert();
        String alertText = alert.getText();
        alert.dismiss(); // alert.accept();

    }/*from  w  w  w  .  j  a  va 2 s.  com*/

}

From source file:com.automationpractice.tests.SaleBanners.java

public static void main(String[] args) {

    //open browser
    System.setProperty("webdriver.chrome.driver", "D:\\selenium test lib\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("http://automationpractice.com");

    //test:/*from ww w. j a va2 s  .  co m*/
    driver.findElement(By.xpath(".//*[@id='htmlcontent_top']/ul/li[1]/a/img")).click();
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='htmlcontent_top']/ul/li[2]/a/img")).click();
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='htmlcontent_home']/ul/li[1]/a/img")).click();
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='htmlcontent_home']/ul/li[2]/a/img")).click();
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='htmlcontent_home']/ul/li[3]/a/img")).click();
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='htmlcontent_home']/ul/li[4]/a/img")).click();
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='htmlcontent_home']/ul/li[5]/a/img")).click();

    driver.quit();

}

From source file:com.automationpractice.tests.SortBy.java

public static void main(String[] args) {

    System.setProperty("webdriver.chrome.driver", "D:\\selenium test lib\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("http://automationpractice.com");

    //this codes is for automated test "sort product" in page "DRESSES" 
    driver.findElement(By.xpath(".//*[@id='block_top_menu']/ul/li[2]/a")).click();
    driver.findElement(By.xpath(".//*[@id='selectProductSort']")).sendKeys("price:asc");
    driver.navigate().back();//  w ww.  j av  a2 s . c o  m
    driver.findElement(By.xpath(".//*[@id='block_top_menu']/ul/li[2]/a")).click();
    driver.findElement(By.xpath(".//*[@id='selectProductSort']")).sendKeys("price:desc");
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='block_top_menu']/ul/li[2]/a")).click();
    driver.findElement(By.xpath(".//*[@id='selectProductSort']")).sendKeys("name:asc");
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='block_top_menu']/ul/li[2]/a")).click();
    driver.findElement(By.xpath(".//*[@id='selectProductSort']")).sendKeys("name:desc");
    driver.quit();
}

From source file:com.axatrikx.webdriver.AxaDriver.java

License:Apache License

/**
 * Checks whether the given string is present in the page or not
 * //from   w w  w. j a  va2s  .  c  om
 * @param
 * @return
 */
public boolean isTextPresent(String searchText) {
    return findElement(By.xpath("//*")).getText().contains(searchText);
}

From source file:com.axatrikx.webdriver.ElementHelper.java

License:Apache License

private By parseLocator(String locator) {
    String locValue;// w ww . j a v a2s .c om
    By byElement = null;
    if (locator.toLowerCase().startsWith("id=")) {
        locValue = locator.substring(3);
        byElement = By.id(locValue);
    } else if (locator.toLowerCase().startsWith("name=")) {
        locValue = locator.substring(5);
        byElement = By.name(locValue);
    } else if (locator.toLowerCase().startsWith("class=")) {
        locValue = locator.substring(6);
        byElement = By.className(locValue);
    } else if (locator.toLowerCase().startsWith("css=")) {
        locValue = locator.substring(4);
        byElement = By.cssSelector(locValue);
    } else if (locator.toLowerCase().startsWith("xpath=")) {
        locValue = locator.substring(6);
        byElement = By.xpath(locValue);
    } else if (locator.toLowerCase().startsWith("classname=")) {
        locValue = locator.substring(10);
        byElement = By.className(locValue);
    } else if (locator.toLowerCase().startsWith("tagname=")) {
        locValue = locator.substring(8);
        byElement = By.tagName(locValue);
    } else if (locator.toLowerCase().startsWith("link=")) {
        locValue = locator.substring(5);
        byElement = By.linkText(locValue);
    } else if (locator.toLowerCase().startsWith("partiallinktext=")) {
        locValue = locator.substring(16);
        byElement = By.partialLinkText(locValue);
    } else {
        // set default to id
        byElement = By.id(locator);
    }
    return byElement;
}