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:co.uniandes.csw.ClinicaDeProblemas.test.UtiTest.java

@Test
public void testUpdateUTI() throws Exception {
    driver.get(baseUrl + "/ClinicaDeProblemas.web/uTI.html");
    //    driver.findElement(By.linkText("Proyectos")).click();
    //Se hace clic en  el vinculo "Edit" del primer elemento de la lista de sports (el elemento que se cre en la anterior prueba)
    driver.findElement(By.linkText("Editar")).click();
    Thread.sleep(2000);//from  w ww .  j ava 2  s .  c  o m
    //Se realiza el mismo proceso de diligenciamento de los campos con los cambios
    driver.findElement(By.id("name")).clear();
    /**
     * Comando que simula la escritura de un valor en el elemento(sendKeys)
     * con el String de parmetro sobre // el elemento encontrado.
     */
    driver.findElement(By.id("name")).sendKeys("taller1");
    driver.findElement(By.id("salon")).clear();
    driver.findElement(By.id("salon")).sendKeys("Salon1");
    driver.findElement(By.id("materia")).clear();
    driver.findElement(By.id("materia")).sendKeys("materia1");
    driver.findElement(By.id("informacion")).clear();
    driver.findElement(By.id("informacion")).sendKeys("info1");

    driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click();
    Thread.sleep(2000);
    //Se verifica que en la lista de respuesta hallan aparecido los cambios en el elemento y tambin el mensaje de edicin exitosa.
    WebElement dialog = driver.findElement(By.xpath("//div[contains(@style,'display: block;')]"));
    List<WebElement> table = driver
            .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr"));
    boolean fail = false;
    for (WebElement webElement : table) {
        List<WebElement> elems = webElement.findElements(By.xpath("td"));

        if (elems.get(0).getText().equals("uTI editada")) {
            fail = true;
        }

    }
    //  driver.findElement(By.linkText("Proyectos")).click();
    /**
     * Comando que realiza click sobre el boton "create" del toolbar. La
     * funcin 'find' encuentra el control y posteriormente hace clic en el
     * mismo. La forma en la que se busca el control es utilizando
     * expresiones xPath ya que los id de los mismos nunca son iguales (se
     * generan con junto con el valor de componentId que vara).
     */
    driver.findElement(By.xpath("//button[contains(@id,'create')]")).click();

    /**
     * Comando que duerme el Thread del test por 2 segundos para dejar que
     * el efecto 'slide down' de backbone abra el formulario de createSport.
     */
    Thread.sleep(2000);

    /**
     * Comando que busca el elemento 'name' en el html actual.
     * Posteriormente limpia su contenido (comando clean).
     */
    driver.findElement(By.id("name")).clear();
    /**
     * Comando que simula la escritura de un valor en el elemento(sendKeys)
     * con el String de parmetro sobre // el elemento encontrado.
     */
    driver.findElement(By.id("name")).clear();
    /**
     * Comando que simula la escritura de un valor en el elemento(sendKeys)
     * con el String de parmetro sobre // el elemento encontrado.
     */
    driver.findElement(By.id("name")).sendKeys("taller1");
    driver.findElement(By.id("salon")).clear();
    driver.findElement(By.id("salon")).sendKeys("Salon1");
    driver.findElement(By.id("materia")).clear();
    driver.findElement(By.id("materia")).sendKeys("materia1");
    driver.findElement(By.id("informacion")).clear();
    driver.findElement(By.id("informacion")).sendKeys("info1");

    Thread.sleep(2000);
    Thread.sleep(2000);
    Thread.sleep(2000);

    driver.findElement(By.xpath("//button[contains(@id,'add')]")).click();
    Thread.sleep(2000);
    Thread.sleep(2000);
    driver.findElement(By.id("selection")).click();
    List<WebElement> a = driver.findElements(By.xpath("//button[contains(@id,'add')]"));
    a.get(1).click();
    a.get(0).click();
    List<WebElement> c = driver.findElements(By.xpath("//button[contains(@id,'save')]"));

    c.get(0).click();

}

From source file:co.uniandes.csw.ClinicaDeProblemas.test.UtiTest.java

@Test
public void testDeleteUTI() throws Exception {
    /**//from   w w w  .  jav a2  s.  com
     * Se hace clic en el vinculo "Delete" del primer elemento de la lista
     * de sports
     */
    driver.get(baseUrl + "/ClinicaDeProblemas.web/uTI.html");
    driver.findElement(By.linkText("Eliminar")).click();
    Thread.sleep(2000);
    /**
     * Se verifica que en la lista el elemento halla desaparecido. Si
     * existe, hubo un error.
     */
    try {
        List<WebElement> table = driver
                .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr"));
        boolean fail = true;
        for (WebElement webElement : table) {
            List<WebElement> elems = webElement.findElements(By.xpath("td"));

        }

        WebElement dialog = driver.findElement(By.xpath("//div[contains(@style,'display: block;')]"));
        // assertTrue(dialog != null && !fail);
    } catch (Exception e) {
        assertTrue(true);
    }

}

From source file:cochrane343.journal.test.JournalStepDefinitions.java

License:Open Source License

private WebElement waitFor(final String text) {
    final String xPath = String.format("//*[@text = '%s' or @content-desc='%s']", text, text);
    final By by = By.xpath(xPath);

    final ExpectedCondition<WebElement> presenceCondition = ExpectedConditions.presenceOfElementLocated(by);
    final WebDriverWait driverWait = new WebDriverWait(driver, WAIT_FOR_ELEMENT_TIMEOUT);

    driverWait.until(presenceCondition);

    return driver.findElement(by);
}

From source file:com.actian.amc.pages.InstanceNewPage.java

public InstanceNewPage instanceCreationWizardScreen2(String cloud, String[] additionalSW) { //added wait statement to check object is avaialable to click
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    try {/* w  ww .  ja  v  a2  s  .c  o  m*/
        String x = "//input[@name='" + cloud + "']";
        if (driver.findElement(By.xpath(x)).isSelected() != true) {
            driver.findElement(By.xpath(x)).click();
        }
        // Choose additional software to provision.
        System.out.println("addition settings=" + additionalSW.length);
        for (int i = 0; i < additionalSW.length; i++) {
            String z = "input[name='" + additionalSW[i] + "']";
            if (driver.findElement(By.cssSelector(z)).isSelected() != true) {
                driver.findElement(By.cssSelector(z)).click();
            }
        }
        clickWizardButton("Wizard 2: ", "Next");
    } catch (NoSuchElementException | StaleElementReferenceException e) {
        System.out.println("Trying to recover from a NoSuchElementException :-");

    }
    return new InstanceNewPage(driver);
}

From source file:com.actian.amc.pages.InstanceNewPage.java

public InstanceNewPage instanceCreationWizardScreen2_2(String ambariVersion, String HDPversion) {
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    System.out.println("hadoopDistribution version :=" + ambariVersion);
    System.out.println("HDPverssion :" + HDPversion);
    int count = 0;

    try {//w  w  w  .ja  v  a 2  s . com
        String z = "input[name='" + ambariVersion + "']";
        if (driver.findElement(By.cssSelector(z)).isSelected() != true) {
            driver.findElement(By.cssSelector(z)).click();
        }
        By dropdown = By.xpath("//input[@name='" + ambariVersion + "']/following::div[4]/div[1]/div[1]");
        driver.findElement(dropdown).click();
        List<WebElement> versions = driver.findElements(itemsInDropdown);
        {
            for (int i = 0; i < versions.size(); i++) {
                if (versions.get(i).getText().equals(HDPversion)) {
                    versions.get(i).click();
                    break;
                }
            }
        } //screenShot(driver);// added to verify ambari versions selection
    } catch (NoSuchElementException | StaleElementReferenceException e) {
        System.out.println("Trying to recover from a NoSuchElementException 2.2:-");

    }
    return new InstanceNewPage(driver);
}

From source file:com.actian.amc.pages.NewCloudDefinitionPage.java

public NewCloudDefinitionPage radioButton_Select(String target_RB) {
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    int count = 0;
    try {//  ww w  . j a  v  a  2  s .co m
        String x = "//input[@name='" + target_RB + "']";
        if (driver.findElement(By.xpath(x)).isSelected() != true) {
            driver.findElement(By.xpath(x)).click();
        }
    } catch (NoSuchElementException | StaleElementReferenceException e) {
        System.out.println("Trying to recover from a stale element :-");
    }
    return new NewCloudDefinitionPage(driver);
}

From source file:com.algomedica.service.AlgomedicaTest.java

@Test
public void NewMachineDetails() throws InterruptedException {

    driver.findElement(By.cssSelector("[class='btn btn-primary pull-left']")).click();

    WebElement MACNo = driver.findElement(By.id("MACNo"));
    MACNo.sendKeys("985921113716");

    WebElement DeviceModel = driver.findElement(By.id("Device Model #"));
    DeviceModel.sendKeys("Dell Thinkpad");

    WebElement DeviceBrandName = driver.findElement(By.id("Device Brand Name"));
    DeviceBrandName.sendKeys("Dell");

    Select lsType = new Select(driver.findElement(By.xpath(
            ".//*[@id='page-wrapper1']/div[3]/div/div[2]/div/div[2]/div[3]/div/form/fieldset/div[2]/div[1]/div/select")));
    ;/*w ww.j a  va2s .  co m*/
    lsType.selectByVisibleText("Trial");

    Select LicenseCategory = new Select(driver.findElement(By.xpath(
            ".//*[@id='page-wrapper1']/div[3]/div/div[2]/div/div[2]/div[3]/div/form/fieldset/div[2]/div[2]/div/select")));
    LicenseCategory.selectByVisibleText("Small");

    WebElement LicenseValidity = driver.findElement(By.id("License Validity"));
    LicenseValidity.sendKeys("30");

    WebElement LicenseCost = driver.findElement(By.id("License Cost"));
    LicenseCost.sendKeys("99");

    WebElement salesOpsName = driver.findElement(By.id("Sales Ops Personnel Name"));
    salesOpsName.sendKeys("rahul");

    WebElement SendEmailTo = driver.findElement(By.id("Send Email To"));
    SendEmailTo.sendKeys("rakesh.pandey@silicus.com");

    driver.findElement(By.cssSelector("[class='btn btn-success ng-scope']")).click();

    Thread.sleep(3000);
    driver.findElement(By.cssSelector("button[class='close']")).click();

    Thread.sleep(3000);
    driver.findElement(By.xpath(".//*[@id='wrapper']/nav/ul/li[1]/a")).click();

    Thread.sleep(3000);
    driver.findElement(By.xpath(".//*[@id='wrapper']/nav/ul/li[2]/a")).click();

    Thread.sleep(3000);
    driver.close();

}

From source file:com.amolik.scrapers.OdishaRationCardScraper.java

public static void processBlock(WebDriver driver, int districtIndex, int blockIndex, String blockValue,
        String blockName, ArrayList<OdishaRationCardBean> beanList) {
    // Select block based upon index

    Select blockSelect = getRefreshedBlockSelect(driver, districtIndex);
    blockSelect.selectByIndex(blockIndex);
    String districtName = districtsNameList.get(districtIndex);

    //      // Create new Directory if not exists
    //      String excelDestDirName = AmolikProperties.getProperty("odisha_ration.excelOutputDir")
    //            +System.getProperty("file.separator")
    //            +districtName;
    ////from   w w w.j a v  a  2 s  .c om
    //      new File(excelDestDirName).mkdirs();
    //
    //      String excelDestFileName = excelDestDirName
    //            +Constants.BACK_SLASH+blockName+".xlsx";

    driver.findElement(By.name(Constants.BTN_SHOW)).click();
    waitForSubmit(driver, Constants.NO_DETAILS_FOUND, blockValue);

    int rowCount = driver.findElements(By.xpath("//table[@id='gvDist']/tbody/tr")).size();

    if (logger.isInfoEnabled()) {

        logger.info(districtIndex + "|" + districtName + "|" + blockIndex + "|" + blockName + "| recordCount="
                + (rowCount - 3)); //$NON-NLS-1$
    }

    // Remove during production
    //rowCount=7;

    if (rowCount > 2) {

        for (int i = 2; i < rowCount - 1; i++) {

            List<WebElement> columns = driver
                    .findElements(By.xpath("//table[@id='gvDist']/tbody/tr[" + (i + 1) + "]/td"));

            StringBuffer columnBuffer = new StringBuffer();

            // Temporary select max columns to process
            int columnToProcess = 5;
            columnToProcess = Math.min(columnToProcess, columns.size());

            OdishaRationCardBean bean = new OdishaRationCardBean();
            setBean(columns, columnToProcess, bean);
            beanList.add(bean);

        }
    }

}

From source file:com.amolik.scrapers.OdishaRationCardScraper.java

public static void waitForBlock(WebDriver driver, String districtValue, String blockText) {

    By byText = By.xpath
    //            ("//select["+
    //              "[@id='ddlDistrict']/option[@value='"+districtValue+"']"+
    //              " and "+
    //            " [@id='ddlBlock']/option[text()='"+blockText+"']"+   
    //            "]");
    ("//select[@id='ddlBlock']/option[text()='" + blockText + "']");

    if (logger.isDebugEnabled()) {

        logger.debug("waitForBlock(" + "WebDriver, String, String) - xpath by string=" + byText.toString()); //$NON-NLS-1$
    }/*from   www .j ava 2 s  .co m*/
    WebElement element = new WebDriverWait(driver, 20)
            .until(ExpectedConditions.presenceOfElementLocated(byText));
}

From source file:com.amolik.scrapers.OdishaRationCardScraper.java

public static void waitForSubmit(WebDriver driver, String emptyText, String dataText) {

    By byText = By.xpath("//table[@id='gvDist']/tbody/tr[1]/td[1][text()='" + emptyText + "']" + "|"
            + "//table[@id='gvDist']/tbody/tr[3]/td[6][contains(text(),'" + dataText + "')]");

    WebElement element = new WebDriverWait(driver, 10)
            .until(ExpectedConditions.presenceOfElementLocated(byText));
}