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:chromedriveryahoologin.ChromeDriverDeleteTrashEmails.java

public static void main(String[] args) {
    try {// w  ww.ja v  a2s.c o m

        Integer pozSpam = 0;
        Integer pozTrash = 0;
        Integer pozHelp = 0;
        Integer pozCompose = 0;
        Integer pozNewFolder = 0;

        System.setProperty("webdriver.chrome.driver",
                "D:\\Proiecte\\selenium-java-2.47.1\\selenium-2.47.1\\chromedriver_win32\\chromedriver.exe");
        System.setProperty("webdriver.chrome.logfile",
                "D:\\prjAutJava\\YahooLogin\\ChromeDriverDeleteSpam.log");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("test-type");
        options.addArguments("--start-maximized");
        options.addArguments("--disable-web-security");
        options.addArguments("--no-proxy-server");
        options.addArguments("--disable-extensions");
        options.addArguments("--disable-notifications");
        options.addArguments("--disable-popup-blocking");
        options.addArguments("--disable-plug-in");
        Map<String, Object> prefs = new HashMap<String, Object>();
        prefs.put("credentials_enable_service", false);
        prefs.put("profile.password_manager_enabled", false);

        options.setExperimentalOption("prefs", prefs);

        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        capabilities.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, true);
        capabilities.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true);
        capabilities.setCapability(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true);
        capabilities.setCapability(CapabilityType.SUPPORTS_ALERTS, true);
        capabilities.setCapability(CapabilityType.PLATFORM, "WIN10");

        driver = new ChromeDriver(capabilities);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get("https://mail.yahoo.com");
        driver.manage().window().maximize();
        WebElement usernameElem = driver.findElement(By.id("login-username"));
        usernameElem.sendKeys("andadeacu@yahoo.com");

        WebElement Next = driver.findElement(By.name("signin"));
        Next.click();

        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        WebElement passwordElem = driver.findElement(By.xpath("//input[@id='login-passwd']"));
        boolean selected = passwordElem.isSelected();

        CharSequence password = "";
        passwordElem.sendKeys(password);

        WebElement login = driver.findElement(By.id("login-signin"));

        login.click();
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        driver.switchTo().activeElement();

        WebElement tooltipElem = driver.findElement(By.xpath("//div[@class='Pos(r) M(0) TooltipContent']"));

        List<WebElement> childs = tooltipElem.findElements(By.xpath("//ul/li"));

        for (int j = 0; j < childs.size(); j++) {

            WebElement spamElem = childs.get(j);
            /*
            * System.out.println("ancorele " + j + " " + " tag " +
            * childs.get(j).getTagName() + " " + childs.get(j).getText() +
            * " " + childs.get(j).getAttribute("innerHTML"));
             */
            if (spamElem.getText().startsWith(("Spam"))) {

                pozSpam = j;

            }
            if (spamElem.getText().startsWith(("Help"))) {

                pozHelp = j;

            }
            if (spamElem.getText().startsWith(("Compose"))) {

                pozCompose = j;

            }
            if (spamElem.getText().startsWith(("New"))) {

                pozNewFolder = j;

            }

            if (spamElem.getText().startsWith(("Trash"))) {
                System.out.println(j + " Trash is " + spamElem.getTagName() + " " + spamElem.getText());
                pozTrash = j;
                break;
            }

        }
        System.out.println(pozTrash);

        WebElement trashElem = childs.get(pozTrash);

        /*
        * System.out.println("trashElem " + trashElem.getTagName() +
        * " text " + trashElem.getText() + " class_atribute " +
        * trashElem.getAttribute("class") + " data_action " +
        * trashElem.getAttribute("data_action"));
         */
        WebElement trashFolderEmpty = trashElem.findElement(
                By.xpath("//a[@class='x-gap btn btn-trash']/span/span[@class='btn icon  icon-delete']"));

        /*
        * System.out.println("spamEmptyFolder " +
        * spamFolderEmpty.getTagName() + " text " +
        * spamFolderEmpty.getText() + " location " +
        * spamFolderEmpty.isEnabled());
         */
        trashFolderEmpty.click();

        int timeOut = 5;

        WebDriverWait wait = new WebDriverWait(driver, timeOut);

        driver.switchTo().alert();

        /* for Chrome is not working 
        WebElement modalPopUp = driver.findElement(By
            .className("modal-hd yui3-widget-hd"));
                
        */

        WebElement btnDeleteSpamEmails = driver.findElement(By.className("btn left right default"));

        /*
        * <button id="okayModalOverlay" class="btn left right default"
        * title="OK" role="button" data-action="ok">OK</button>
         */
        btnDeleteSpamEmails.click();

        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        driver.switchTo().activeElement();

        // verify msg after you delete spam emails
        System.out.println(driver.getCurrentUrl());

        driver.quit();
    } catch (Exception ex) {

        ex.printStackTrace();
        driver.quit();
    }

}

From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java

public void enterDealerName(String dealerNameString) throws Throwable {
    WebElement dealerName = driver.findElement(By.xpath(
            "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[1]/div[1]/div/input"));
    dealerName.clear();/*from w  w w  . ja  va 2 s  . c o m*/
    dealerName.sendKeys(dealerNameString);
}

From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java

public void clickGetInfo() throws Throwable {
    WebElement getInfoBtn = driver.findElement(By.xpath(
            "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[1]/div[2]/div/button"));
    getInfoBtn.click();//from  w w w . j a  v a  2 s . c o  m
}

From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java

public void selectCarDealerType(String carDealerTypeString) throws Throwable {
    WebElement carDealerType = driver.findElement(By.xpath(
            "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[2]/fieldset/div[1]/div/select"));
    Select mySelect = new Select(carDealerType);
    mySelect.selectByVisibleText(carDealerTypeString);
}

From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java

public void enterContactName(String contactNameString) throws Throwable {
    WebElement contactName = driver.findElement(By.xpath(
            "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[3]/div[1]/div/input"));
    contactName.clear();/* w  ww  . j a  v  a  2  s.co  m*/
    contactName.sendKeys(contactNameString);
}

From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java

public void enterContactPhone(String contactPhoneString) throws Throwable {
    WebElement contactPhone = driver.findElement(By.xpath(
            "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[3]/div[2]/div/input"));
    contactPhone.clear();/*from  www .j  a v  a 2s  .c  o m*/
    contactPhone.sendKeys(contactPhoneString);
}

From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java

public void selectDiscount(String isDiscount) throws Throwable {
    WebElement discount = driver.findElement(By.xpath(
            "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[3]/div[3]/div/label[1]/input"));
    WebElement unDiscount = driver.findElement(By.xpath(
            "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[3]/div[3]/div/label[2]/input"));
    if (isDiscount.equalsIgnoreCase("true") == true) {
        discount.click();//from  w  w  w  .  j  a v a2  s. c om
    } else {
        unDiscount.click();
    }
}

From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java

public void selectProvince(String province) throws Throwable {
    WebElement provinceSelect = driver.findElement(By.xpath(
            "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[4]/div[1]/div/select"));
    Select mySelect = new Select(provinceSelect);
    mySelect.selectByVisibleText(province);
    Thread.sleep(1000);//from w w w  .j  a  va  2s  .co  m
}

From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java

public void selectCity(String city) throws Throwable {
    WebElement citySelect = driver.findElement(By.xpath(
            "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[4]/div[2]/div/select"));
    Select mySelect = new Select(citySelect);
    mySelect.selectByVisibleText(city);/*from  w  w  w .j a  v  a 2  s.  co  m*/
    Thread.sleep(1000);
}

From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java

public void selectArea(String area) throws Throwable {
    WebElement areaSelect = driver.findElement(By.xpath(
            "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[4]/div[3]/div/select"));
    Select mySelect = new Select(areaSelect);
    mySelect.selectByVisibleText(area);//from   w w w . ja  v  a  2 s. c  o  m
}