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:akori.Features.java

public static void traverse(Element e, int level, int index, String xpath, int siblings, PrintWriter writer,
        WebDriver driver) {//from   w w  w.j av  a 2 s .c o  m

    if (siblings > 1) {
        WebElement webe = null;
        try {
            webe = driver.findElement(By.xpath("/" + xpath + "/" + e.nodeName() + "[" + index + "]"));
        } catch (Exception exp) {
            System.out.println("exception no se encontro");
        }
        if (webe != null) {
            Point po = webe.getLocation();
            Dimension d = webe.getSize();
            if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0) {
                System.out.println("elemento negativo");
            } else {
                writer.println("/" + xpath + "/" + e.nodeName() + "[" + index + "]," + e.nodeName() + "," + po.x
                        + "," + po.y + "," + d.width + "," + d.height + "," + level);
            }
        }
    } else {
        WebElement webe = null;
        try {
            webe = driver.findElement(By.xpath("/" + xpath + "/" + e.nodeName()));
        } catch (Exception exp) {
            System.out.println("exception no se encontro");
        }
        if (webe != null) {
            Point po = webe.getLocation();
            Dimension d = webe.getSize();
            if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0) {
                System.out.println("elemento negativo");
            } else {
                writer.println("/" + xpath + "/" + e.nodeName() + "," + e.nodeName() + "," + po.x + "," + po.y
                        + "," + d.width + "," + d.height + "," + level);
            }
        }
    }

    int childSize = e.children().size();
    Elements children = e.children();
    int i = 1;
    for (Element temp : children) {
        if (siblings > 1) {
            traverse(temp, level + 1, i, xpath + "/" + e.nodeName() + "[" + index + "]", childSize, writer,
                    driver);
        } else {
            traverse(temp, level + 1, i, xpath + "/" + e.nodeName(), childSize, writer, driver);
        }
        ++i;
    }

}

From source file:all_iterations_scripts.US954_Resume_Attachment.java

@Test
public void testSmokeLogin_Maintest() throws Exception {
    //Step 1 - Open QA site   
    driver.get(Constants.baseUrl);//  www. j  a  v a 2  s  .  c o m
    System.out.println("Step 1 - URL: " + Constants.baseUrl);

    //Click on the Login link and log in
    Thread.sleep(2000);
    driver.findElement(By.xpath(".//*[@id='gov_login_box']/form[1]/button")).click();

    //Enter a valid Login ID
    driver.findElement(By.xpath(".//*[@id='user_email']")).clear();
    driver.findElement(By.xpath(".//*[@id='user_email']")).sendKeys(Constants.LLC_Login);
    System.out.println("  Login ID: " + Constants.LLC_Login);

    //Enter a valid Password
    driver.findElement(By.xpath(".//*[@id='user_password']")).clear();
    driver.findElement(By.xpath(".//*[@id='user_password']")).sendKeys(Constants.Password);
    System.out.println("  Password: " + Constants.Password);

    //Click the Sign-in button
    driver.findElement(By.xpath(".//*[@id='business_signin']")).click();
    System.out.println("  Click on Login Link and log in");

    //Close pop up window   
    Thread.sleep(2000);
    if (driver.getPageSource().contains("Signed in successfully")) {
        driver.findElement(By.xpath(".//*[@id='labelid']")).click();
    } else {
        System.out.println("  Successful sign in alert message not present");
    }

    //Verify if there is an existing certification on the dashboard and delete to start a new certification.
    if (driver.getPageSource().contains("Draft")) {
        driver.findElement(By.xpath(".//*[@id='dashboard-index']/div[4]/div[2]/table/tbody/tr/td[4]/a[2]"))
                .click();
        Thread.sleep(2000);
        System.out.println("WOSB Certification in-progress on the dashboard was deleted");
        driver.switchTo().alert().accept();
        Thread.sleep(7000);
    } else {
        System.out.println(
                "There was no WOSB certification in-progress on the dashboard, a new certification is being created");
    }

    //Step 2 - Answer questions for WOSB application
    // Locate the Certifications on the dashboard, click on it and select WOSB to continue.
    driver.findElement(By.xpath(".//*[@id='js-navigation-menu']/li[2]/a")).click();
    driver.findElement(By.xpath(".//*[@id='js-navigation-menu']/li[2]/ul/li[1]/a")).click();
    Thread.sleep(2000);
    //Locate the accept button at the bottom of the WOSB agreement and click on it to continue.
    driver.findElement(By.xpath(".//*[@id='new_sba_application']/input[3]")).click();
    Thread.sleep(2000);
    //Locate the 8(a) question and select No and continue.
    driver.findElement(By.xpath(".//*[@id='answers[5][value]']/label[2]")).click();
    driver.findElement(By.xpath(".//*[@id='wosb']/input[4]")).click();
    System.out.println("  8(a) question has been answered");
    //Locate the Third Party Certification, question1 and select No and continue.
    driver.findElement(By.xpath(".//*[@id='answers[6][value]']/label[2]")).click();
    driver.findElement(By.xpath(".//*[@id='wosb']/input[4]")).click();
    //Locate the Non-qualification, question and select No and continue.
    driver.findElement(By.xpath(".//*[@id='answers[8][value]']/label[2]")).click();
    driver.findElement(By.xpath(".//*[@id='wosb']/input[4]")).click();
    System.out.println("  Third Party questions have been answered");
    //Locate the LLC questions, select No and continue.
    driver.findElement(By.xpath(".//*[@id='answers[18][value]']/label[2]")).click();
    driver.findElement(By.xpath(".//*[@id='answers_18_comment']")).sendKeys(Constants.comment);
    driver.findElement(By.xpath(".//*[@id='answers[19][value]']/label[2]")).click();
    driver.findElement(By.xpath(".//*[@id='answers_19_comment']")).sendKeys(Constants.comment);
    driver.findElement(By.xpath(".//*[@id='wosb']/input[4]")).click();
    System.out.println("  LLC questions have been answered");
    //Locate the Citizenship & Ownership questions, select No and continue.
    driver.findElement(By.xpath(".//*[@id='answers[20][value]']/label[2]")).click();
    driver.findElement(By.xpath(".//*[@id='answers[21][value]']/label[2]")).click();
    driver.findElement(By.xpath(".//*[@id='wosb']/input[4]")).click();
    System.out.println("  Citizenship & Ownership questions have been answered");
    //Locate the Business & Trusts questions, select No and continue.
    driver.findElement(By.xpath(".//*[@id='answers[22][value]']/label[2]")).click();
    driver.findElement(By.xpath(".//*[@id='answers[23][value]']/label[2]")).click();
    driver.findElement(By.xpath(".//*[@id='wosb']/input[4]")).click();
    System.out.println("  Business & Trusts questions have been answered");
    //Locate the first Operations & Management question and select No.
    driver.findElement(By.xpath(".//*[@id='answers[24][value]']/label[2]")).click();
    System.out.println("  The first Operations & Management question have been answered");

    //********************************************
    //Start of US954
    //Verify that Non Corp applicant's don't see Corp questions

    //Step 3 - Verify that the second question needs to be answered before moving on.
    System.out.println("Step 3 - Verify that the second question needs to be answered before moving on");
    driver.findElement(By.xpath(".//*[@id='wosb']/input[4]")).click();
    try {
        assertEquals("Please answer this question",
                driver.findElement(By.xpath(".//*[@id='answers[25][value]-error']")).getText());
        System.out.println("  Question has to be answered - Pass");
    } catch (Error e) {
        verificationErrors.append(e.toString());
        System.out.println("  Question has to be answered - <<FAILED>>");
        driver.quit();
    }
    Thread.sleep(2000);

    //Step 4 - Verify that the second question's Details for Operations & Management has been updated.
    System.out.println(
            "Step 4 - Verify that the second question's Details for Operations & Management has been updated");
    try {
        assertEquals(
                "(Resume Optional) The woman must have managerial experience of the extent and complexity needed to run the concern. The woman manager need not have the technical expertise or possess the required license to be found to control the concern if she can demonstrate that she has ultimate managerial and supervisory control over those who possess the required licenses or technical expertise. However, if a man possesses the required license and has an equity interest in the concern, he may be found to control the concern.",
                driver.findElement(By.xpath(".//*[@id='collapsible-25']/div/p")).getText());
        System.out.println("  Question has been updated - Pass");
    } catch (Error e) {
        verificationErrors.append(e.toString());
        System.out.println("  Question has been updated - <<FAILED>>");
        driver.quit();
    }
    Thread.sleep(2000);

    //Step 5 - Select No and move to the Expertise & Employment screen    
    System.out.println("Step 5 - Select No and move to the Expertise & Employment screen");
    driver.findElement(By.xpath(".//*[@id='answers[25][value]']/label[2]")).click();
    driver.findElement(By.xpath(".//*[@id='wosb']/input[4]")).click();
    Thread.sleep(2000);

    //Step 6 - Verify that the Expertise & Employment screen is displayed
    System.out.println("Step 6 - Verify that the Expertise & Employment screen is displyed");
    try {
        assertEquals("Expertise & Employment",
                driver.findElement(By.xpath(".//*[@id='main-content']/div/h2")).getText());
        System.out.println("  Expertise & Employment screen is displayed - Pass");
    } catch (Error e) {
        verificationErrors.append(e.toString());
        System.out.println("  Expertise & Employment screen is displayed - <<FAILED>>");
        driver.quit();
    }
    Thread.sleep(2000);

    //Step 7 - Return to the Operations & Management screen
    System.out.println("Step 7 - Return to the Operations & Management screen");
    driver.findElement(By.xpath(".//*[@id='operations_part_3']")).click();
    try {
        assertEquals("Operations & Management",
                driver.findElement(By.xpath(".//*[@id='main-content']/div/h2")).getText());
        System.out.println("  Operation & Management screen is displayed - Pass");
    } catch (Error e) {
        verificationErrors.append(e.toString());
        System.out.println("  Operation & Management screen is displayed - <<FAILED>>");
        driver.quit();
    }
    Thread.sleep(2000);

    //Step 8 - Select Yes to the second Operation & Management question
    System.out.println("Step 8 - Select Yes to the second Operation & Management question");
    driver.findElement(By.xpath(".//*[@id='answers[25][value]']/label[1]")).click();

    //Step 9 - Verify that the Upload button is displayed
    System.out.println("Step 9 - Verify that the Upload button is displayed");
    try {
        assertEquals("Upload",
                driver.findElement(By.xpath(".//*[@id='answers[25][attachment]']/div/label")).getText());
        System.out.println("  Upload button is displayed - Pass");
    } catch (Error e) {
        verificationErrors.append(e.toString());
        System.out.println("  Upload button is displayed - <<FAILED>>");
        driver.quit();
    }
    Thread.sleep(2000);

    //Step 10 - Verify that a upload is optional by clicking the Save and continue button
    System.out.println("Step 10 - Verify that a upload is optional by clicking the Save and continue button");
    driver.findElement(By.xpath(".//*[@id='wosb']/input[4]")).click();
    Thread.sleep(2000);
    try {
        assertEquals("Expertise & Employment",
                driver.findElement(By.xpath(".//*[@id='main-content']/div/h2")).getText());
        System.out.println("  Upload is optional, the Expertise & Employment screen is displayed - Pass");
    } catch (Error e) {
        verificationErrors.append(e.toString());
        System.out.println("  Upload is optional, the Expertise & Employment screen is displayed - <<FAILED>>");
        driver.quit();
    }
    Thread.sleep(2000);

    //Step 11 - Return to the Operations & Management screen
    System.out.println("Step 11 - Return to the Operations & Management screen");
    driver.findElement(By.xpath(".//*[@id='operations_part_3']")).click();
    try {
        assertEquals("Operations & Management",
                driver.findElement(By.xpath(".//*[@id='main-content']/div/h2")).getText());
        System.out.println("  Operation & Management screen is displayed - Pass");
    } catch (Error e) {
        verificationErrors.append(e.toString());
        System.out.println("  Operation & Management screen is displayed - <<FAILED>>");
        driver.quit();
    }
    Thread.sleep(2000);

    //Step 12 - Click the Dashboard link
    driver.findElement(By.xpath(".//*[@id='js-navigation-menu']/li[1]/a")).click();
    Thread.sleep(2000);
    System.out.println("Step 12 - Returned to the Dashboard");

    //Step 13 - Click the Logout link
    System.out.println("Step 13 - Logout link clicked");
    driver.findElement(By.xpath(".//*[@id='js-navigation-menu']/li[6]/a")).click();
    Thread.sleep(3000);
    driver.findElement(By.xpath(".//*[@id='labelid']")).click();
    Thread.sleep(2000);
    System.out.println("END OF TEST");
}

From source file:AM.Physician.AddNewPhysician.java

public static Select lst_AP_InternalLiaison(WebDriver driver) {
    element = driver.findElement(By.xpath("//*[@id='PhysicianForm']/div[2]/div[4]/ul/li/select"));
    list = new Select(driver.findElement(By.xpath("//*[@id='PhysicianForm']/div[2]/div[4]/ul/li/select")));
    Waits.ForElementVisibility(driver, element);
    return list;//from  w ww  .j  a va 2s.co m
}

From source file:AM.Physician.AddNewPhysician.java

public static WebElement txt_AP_Comments(WebDriver driver) {
    element = driver.findElement(By.xpath("//*[@id='PhysicianForm']/div[2]/div[6]/ul/textarea"));
    Waits.ForElementVisibility(driver, element);
    return element;
}

From source file:app.Stepdefs.java

@When("^Delete is pressed$")
public void delete_() throws InterruptedException {
    // this will make the popup visible
    driver.findElement(By.xpath("/html/body/div/div/div/form[2]/input[2]")).click();
    Thread.sleep(2000); // If you wanna see the popup for 2 seconds
}

From source file:applango.common.services.Applango.genericApplangoWebsiteActions.java

public static void clickOnSubmitCredentials(WebDriver driver) throws IOException {
    Map appObjectMapper = objectMapper.getObjectMap(jsonMaps.APPLANGO);
    String loginSubmit = appObjectMapper.get(LOGIN_SUBMIT_UI_OBJECT).toString();
    driver.findElement(By.xpath(loginSubmit)).click();
}

From source file:applango.common.services.Applango.genericApplangoWebsiteActions.java

private static void clickOnAccount(WebDriver driver1) throws IOException {
    driver1.findElement(By.xpath(applangoButtons.ACCOUNT.getValue().toString())).click();
}

From source file:applango.common.services.Applango.genericApplangoWebsiteActions.java

private static void clickOnLogout(WebDriver driver1) throws IOException {
    driver1.findElement(By.xpath(applangoButtons.LOGOUT.getValue().toString())).click();
}

From source file:applango.common.services.Applango.genericApplangoWebsiteActions.java

private static void openUserMenu(WebDriver driver1) throws IOException {
    driver1.findElement(By.xpath(applangoDropdowns.USER_MENU.getValue().toString())).click();
}

From source file:applango.common.services.Applango.genericApplangoWebsiteActions.java

public static void clickOnApplicationSettings(WebDriver driver1, WebDriverWait wait1) throws IOException {
    driver1.findElement(By.xpath("/html/body/span/span/div[2]/div/span/div/div/img")).click();
    //        driver1.findElement(By.cssSelector(applangoButtons.AUTHENTICATION_SETTINGS.getValue().toString())).click();
    waitForAuthenticationScreen(wait1);//  w  w w  .j ava2  s . com
}