Example usage for org.openqa.selenium By cssSelector

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

Introduction

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

Prototype

public static By cssSelector(String cssSelector) 

Source Link

Document

Find elements via the driver's underlying W3C Selector engine.

Usage

From source file:ExpiredLicenseSelenium.java

@Test
public void testAddLicenseWebDriver() throws Exception {
    Date now = new java.util.Date();
    String ts = new Timestamp(now.getTime()).toString();
    String validTill = addDays(now, 15);

    driver.get(baseUrl + "#/");
    driver.findElement(By.linkText("Start licensing process")).click();
    driver.findElement(By.id("nameOrganization")).clear();
    driver.findElement(By.id("nameOrganization")).sendKeys(ts);
    driver.findElement(By.id("applicationArea")).clear();
    driver.findElement(By.id("applicationArea")).sendKeys("ApplicationAreaTest");
    driver.findElement(By.id("nameContact")).clear();
    driver.findElement(By.id("nameContact")).sendKeys("NameTest");
    driver.findElement(By.id("email")).clear();
    driver.findElement(By.id("email")).sendKeys("email@test");
    driver.findElement(By.id("skype")).clear();
    driver.findElement(By.id("skype")).sendKeys("SkypeTest");
    driver.findElement(By.id("phone")).clear();
    driver.findElement(By.id("phone")).sendKeys("PhoneTest");
    driver.findElement(By.cssSelector("div.form-group > button.btn.btn-default")).click();
    new Select(driver.findElement(By.id("product"))).selectByVisibleText("i-Voting 11.2");
    driver.findElement(/*from   w  w w  .  j a  v  a  2 s  .c  o m*/
            By.cssSelector("form[name=\"chooseProductForm\"] > div.form-group > button.btn.btn-default"))
            .click();
    driver.findElement(By.id("validFrom")).clear();
    driver.findElement(By.id("validFrom")).sendKeys("1900-01-01");
    driver.findElement(By.id("validTill")).clear();
    driver.findElement(By.id("validTill")).sendKeys(validTill);
    driver.findElement(By.id("addLicenseSubmit")).click();
    //Check if license is expiring
    driver.findElement(By.xpath("//div[@id='bs-example-navbar-collapse-1']/ul[2]/li[2]/a/span/i[2]")).click();
    //TODO Add a check based on id instead of validFrom/validTill dates
    List<WebElement> list = driver.findElements(By.xpath("//*[contains(text(),'" + "1900-01-01" + "')]"));
    Assert.assertTrue("License not found!", list.size() > 0);
    List<WebElement> list2 = driver.findElements(By.xpath("//*[contains(text(),'" + validTill + "')]"));
    Assert.assertTrue("License not found!", list2.size() > 0);
}

From source file:seleniumTester.java

@Test
public void test_5() {
    List<WebElement> tds = driver.findElement(By.id("tbodycars")).findElements(By.cssSelector("tr")).get(0)
            .findElements(By.tagName("td"));
    tds.get(7).findElements(By.tagName("a")).get(0).click();
    WebElement element = driver.findElement(By.id("description"));
    element.sendKeys(Keys.CONTROL + "a");
    element.sendKeys(Keys.DELETE);//from   ww  w.  ja  v  a 2 s  .  co  m
    element.sendKeys("Cool car");
    driver.findElement(By.id("save")).click();

    (new WebDriverWait(driver, WAIT_MAX)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            WebElement e = d.findElement(By.tagName("tbody"));
            List<WebElement> rows = e.findElements(By.tagName("tr"));
            String result = null;
            for (int i = 0; i < rows.size(); i++) {
                if (rows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) {
                    result = rows.get(i).findElements(By.tagName("td")).get(5).getText();
                    break;
                }
            }
            assertThat(result, is("Cool car"));
            return true;
        }
    });
}

From source file:seleniumTester.java

@Test
public void test_6() {
    driver.findElement(By.id("new")).click();
    driver.findElement(By.id("save")).click();
    int size = driver.findElement(By.id("tbodycars")).findElements(By.cssSelector("tr")).size();

    String errorMsg = driver.findElement(By.id("submiterr")).getText();
    assertThat(errorMsg, is("All fields are required"));
    assertThat(size, is(5));//from  w  w  w  . j a  v  a  2s  .co m

}

From source file:StateContentTest.java

public void selectState(String state) throws InterruptedException {
    try {//from w  w w .  ja  v a2s . c om
        new Select(driver.findElement(By.id("statesel"))).selectByVisibleText(state);
        driver.findElement(By.id("stateSelectionContinue")).click();
    } catch (WebDriverException w) {
        driver.findElement(By.cssSelector("div.select-state > a")).click();
        Thread.sleep(1000);
        new Select(driver.findElement(By.id("statesel"))).selectByVisibleText(state);
        driver.findElement(By.id("stateSelectionContinue")).click();
    }
}

From source file:StateContentTest.java

public void testFAQPage(String state) throws InterruptedException {
    driver.findElement(By.linkText("FAQs")).click();

    /*Test "How Long is this course" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[6]/div/h3/span")).click();
    Thread.sleep(300);//  w ww  .  ja  v  a 2  s  . co  m
    assertEquals(copyMatrix.get(state)[1].trim(),
            driver.findElement(By.cssSelector("#collapse6 > div.panel-body > p")).getText().trim());

    /*Test "Can I start the online version of the AARP Smart Driver course at a computer in one location and continue at another?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[7]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[2].trim(),
            driver.findElement(By.cssSelector("#collapse7 > div.panel-body > p")).getText().trim());

    /*Test "How do I navigate the online course?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[8]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[7].trim(),
            driver.findElement(By.cssSelector("#collapse8 > div.panel-body")).getText().trim());

    /*Test "Is this online version of the AARP Smart Driver course narrated or just text?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[9]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[8].trim(),
            driver.findElement(By.cssSelector("#collapse9 > div.panel-body > p")).getText().trim());

    /*Test "Quizzes and Exams: Will those be recorded and graded? Can I fail the course?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[10]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[9].trim(),
            driver.findElement(By.cssSelector("#collapse10 > div.panel-body")).getText().trim());

    /*Test "What is the cost of the course and how do I pay" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[1]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[13].trim(),
            driver.findElement(By.cssSelector("#collapse1 > div.panel-body")).getText().trim());

    /*Test "Is it safe to send my credit card information over the internet?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[2]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[14].trim(),
            driver.findElement(By.cssSelector("#collapse2 > div.panel-body")).getText().trim());

    /*Test "What information do I need handy for registering?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[4]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[15].trim(),
            driver.findElement(By.cssSelector("#collapse4 > div.panel-body")).getText().trim());

    /*Test "Why does AARP Driver Safety ask for my driver's license number and date of birth when I register for the AARP Smart Driver course?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[5]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[16].trim(),
            driver.findElement(By.cssSelector("#collapse5 > div.panel-body")).getText().trim());

    /*Test "If I can't finish the course or don't wish to continue it, will I be able to receive a refund?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[3]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[17].trim(),
            driver.findElement(By.cssSelector("#collapse3 > div.panel-body")).getText().trim());

    /*Test "System Requirements for taking the AARP Smart Driver course online:" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[13]/div/h3/span")).click();
    Thread.sleep(300);
    driver.findElement(By.cssSelector("span.sys-link")).click();
    assertEquals(copyMatrix.get(state)[18].trim(),
            driver.findElement(By.cssSelector("#collapse13 > div.panel-body")).getText().trim());

    /*Test "What happens if I get disconnected?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[11]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[19].trim(),
            driver.findElement(By.cssSelector("#collapse11 > div.panel-body")).getText().trim());

    /*Test "What happens if I have problems while taking the course or the system malfunctions for any reason?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[12]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[20].trim(),
            driver.findElement(By.cssSelector("#collapse12 > div.panel-body")).getText().trim());
}

From source file:StateContentTest.java

public void testWhyTakePage(String state) {
    driver.findElement(By.xpath("//a[contains(text(),'Why Take Our Course?')]")).click();

    assertEquals(copyMatrix.get(state)[4].trim(),
            driver.findElement(By.cssSelector("div.state-holder > p")).getText().trim());
}

From source file:StateContentTest.java

public void testPricingPage(String state) {
    driver.findElement(By.xpath("//a[contains(text(),'Pricing')]")).click();

    assertEquals(copyMatrix.get(state)[4].trim(),
            driver.findElement(By.cssSelector("div.course-text")).getText().trim());
}

From source file:StateContentTest.java

public void testSignUpPage(String state) throws InterruptedException {
    driver.findElement(By.cssSelector("a.btn.btn-primary")).click();

    assertEquals(copyMatrix.get(state)[4].trim(),
            driver.findElement(By.id("courseReasonDesc")).getText().trim());

    driver.findElement(By.id("confirmState")).click();
    Thread.sleep(300);//from w  w w  .  j  a v  a 2s  .co  m

    switch (state) {
    case "Alaska":
    case "California":
    case "Delaware":
    case "District of Columbia":
    case "Michigan":
    case "Minnesota":
    case "Pennsylvania":
    case "West Virginia":
        assertEquals(copyMatrix.get(state)[5].trim(),
                driver.findElement(By.id("id=REFRESHER-Q")).getText().trim());
        driver.findElement(By.xpath("(//a[contains(text(),'?')])[3]")).click();
        Thread.sleep(300);
        assertEquals(copyMatrix.get(state)[6].trim(),
                driver.findElement(By.id("id=REFRESHER-TIP")).getText().trim());
        driver.findElement(By.cssSelector(
                "#refresherpop > div.modal-dialog > div.modal-content > div.modal-header > button.close.btn-close"))
                .click();

        new Select(driver.findElement(By.id("DLTYPE"))).selectByVisibleText("CLASS A");
        new Select(driver.findElement(By.id("COURSEREASON"))).selectByVisibleText("Court Referral");
    default:
        driver.findElement(By.id("continueCourseOptions")).click();
        break;
    }
    Thread.sleep(300);

    driver.findElement(By.id("CCNAME")).clear();
    driver.findElement(By.id("CCNAME")).sendKeys("test test");
    driver.findElement(By.id("cc")).clear();
    driver.findElement(By.id("cc")).sendKeys("4111111111111111");
    new Select(driver.findElement(By.id("CCMONTH"))).selectByVisibleText("04 (Apr)");
    new Select(driver.findElement(By.id("CCYEAR"))).selectByVisibleText("2018");
    driver.findElement(By.id("CCCVV")).clear();
    driver.findElement(By.id("CCCVV")).sendKeys("0000");
    driver.findElement(By.id("CCEMAIL")).clear();
    driver.findElement(By.id("CCEMAIL")).sendKeys("kyle.erickson@thomasarts.com");
    driver.findElement(By.id("CCCEMAIL")).clear();
    driver.findElement(By.id("CCCEMAIL")).sendKeys("kyle.erickson@thomasarts.com");
    driver.findElement(By.id("PASSWORD")).clear();
    driver.findElement(By.id("PASSWORD")).sendKeys("password1");
    driver.findElement(By.id("CPASSWORD")).clear();
    driver.findElement(By.id("CPASSWORD")).sendKeys("password1");
    driver.findElement(By.id("TERMS")).click();
    driver.findElement(By.id("coursePurchase")).click();

    Thread.sleep(300);
    //assertEquals("Thank you for your purchase!", driver.findElement(By.cssSelector("h1")).getText());

    //      driver.findElement(By.id("FIRSTNAME")).clear();
    //      driver.findElement(By.id("FIRSTNAME")).sendKeys("test");
    //      driver.findElement(By.id("LASTNAME")).clear();
    //      driver.findElement(By.id("LASTNAME")).sendKeys("test");
    //      driver.findElement(By.id("ADDRESS1")).clear();
    //      driver.findElement(By.id("ADDRESS1")).sendKeys("555 fake st.");
    //      driver.findElement(By.id("CITY")).clear();
    //      driver.findElement(By.id("CITY")).sendKeys("faketown");
    //      driver.findElement(By.id("ZIP")).clear();
    //      driver.findElement(By.id("ZIP")).sendKeys("84015");
    //      new Select(driver.findElement(By.id("DATEOFBIRTH_MONTH"))).selectByVisibleText("MAY");
    //      new Select(driver.findElement(By.id("DATEOFBIRTH_DAY"))).selectByVisibleText("4");
    //      new Select(driver.findElement(By.id("DATEOFBIRTH_YEAR"))).selectByVisibleText("1915");
    //      driver.findElement(By.id("radio")).click();
    //      driver.findElement(By.id("PHONE")).clear();
    //      driver.findElement(By.id("PHONE")).sendKeys("555-555-5555");
    //      driver.findElement(By.id("DL")).clear();
    //      driver.findElement(By.id("DL")).sendKeys("555555555");
    //      driver.findElement(By.name("submit")).click();
}

From source file:StateContentTest.java

public void testGiftPaymentPage(String state) throws InterruptedException {
    loadPage(false);//from  w  ww  . ja  v a2 s.  co m
    driver.findElement(By.xpath("//a[contains(text(),'Purchase the course as a gift')]")).click();

    driver.findElement(By.cssSelector("p.sta-link > a > span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[21].trim(),
            driver.findElement(By.cssSelector(
                    "#stateInfo-gifter > div.modal-dialog > div.modal-content > div.modal-body > p")).getText()
                    .trim());
    driver.findElement(By.cssSelector(
            "#stateInfo-gifter > div.modal-dialog > div.modal-content > div.modal-header > button.close.btn-close"))
            .click();
    Thread.sleep(300);
    driver.findElement(By.id("confirmState")).click();

    driver.findElement(By.id("RNAME")).clear();
    driver.findElement(By.id("RNAME")).sendKeys("Test Test");
    driver.findElement(By.id("REMAIL")).clear();
    driver.findElement(By.id("REMAIL")).sendKeys("test@test.test");
    driver.findElement(By.id("CREMAIL")).clear();
    driver.findElement(By.id("CREMAIL")).sendKeys("test@test.test");
    driver.findElement(By.id("FROMANME")).clear();
    driver.findElement(By.id("FROMANME")).sendKeys("test");
    driver.findElement(By.id("continueCourseOptions")).click();

    driver.findElement(By.id("CCNAME")).clear();
    driver.findElement(By.id("CCNAME")).sendKeys("test");
    driver.findElement(By.id("cc")).clear();
    driver.findElement(By.id("cc")).sendKeys("4111111111111111");
    new Select(driver.findElement(By.id("CCMONTH"))).selectByVisibleText("04 (Apr)");
    new Select(driver.findElement(By.id("CCYEAR"))).selectByVisibleText("2018");
    driver.findElement(By.id("CCCVV")).clear();
    driver.findElement(By.id("CCCVV")).sendKeys("0000");
    driver.findElement(By.id("CCEMAIL")).clear();
    driver.findElement(By.id("CCEMAIL")).sendKeys("test@test.test");
    driver.findElement(By.id("CCCEMAIL")).clear();
    driver.findElement(By.id("CCCEMAIL")).sendKeys("test@test.test");
    driver.findElement(By.id("TERMS")).click();
    driver.findElement(By.id("coursePurchase")).click();

    Thread.sleep(3000);

    assertEquals("Thank you for your gift purchase!", driver.findElement(By.cssSelector("h1")).getText());
}

From source file:SamlLoginAcceptanceTests.java

License:Open Source License

private void samlPhpLogin(String linkText) {
    webDriver.get(baseUrl + "/login");
    Assert.assertEquals("Cloud Foundry", webDriver.getTitle());
    webDriver.findElement(By.xpath("//a[text()='" + linkText + "']")).click();
    webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]"));
    webDriver.findElement(By.name("username")).clear();
    webDriver.findElement(By.name("username")).sendKeys("marissa");
    webDriver.findElement(By.name("password")).sendKeys("koala");
    webDriver.findElement(By.xpath("//input[@value='Login']")).click();
    assertEquals("marissa@test.org",
            webDriver.findElement(By.xpath("//div[@class='dropdown-trigger']")).getText());
    assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to?"));
}