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:au.edu.qtac.admission.webtest.LoginPage.java

public String getResultMessage() {
    final String msg = driver.findElement(By.cssSelector("div.ui-growl-item-container")).getText();
    return msg;
}

From source file:automated_tests.InitialPopups.java

@Test(priority = 0)
public static void checkConsentToUseText() {

    loadMPNPage();//from   www .j a va  2 s.c  om
    try {
        assertEquals(
                "This application is intended for use by licensed healthcare practitioners and is prepared in English only. At this time, application use should be limited to those countries accepting labeling in English for professional use - United Kingdom, Ireland, Cyprus, Luxembourg, Malta, Poland, Bulgaria, and Latvia. This application was validated to the most recent browser capability at the time of launch - if this application is not working on your browser please contact trd_ussc.complaints@novartis.com.",
                driver.findElement(By.cssSelector("#ui-id-1 > div.next_text.mt40 > span")).getText());
        System.out.println("Consent to Use text is correct");
    } catch (Error e) {
        verificationErrors.append(e.toString());
    }
}

From source file:automated_tests.InitialPopups.java

@Test(priority = 1)
public void rejectConsentToUse() {
    driver.findElement(By.id("btnDoNotConsent")).click();

    //TODO: Look into $.tablesorter is undefined Javascript error
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("no_html5")));

    try {//from   www. j  ava  2 s  . c  o m
        assertEquals("This application can only be used after accepting the Terms of Use and Privacy Policy",
                driver.findElement(By.cssSelector("span")).getText());
        System.out.println("Rejected terms of use warning text correct");
    } catch (Error e) {
        verificationErrors.append(e.toString());
    }
}

From source file:automated_tests.InitialPopups.java

@Test(priority = 3)
public void rejectTermsOfUse() {
    driver.findElement(By.id("btnRejectTerms")).click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("no_html5")));

    try {/*from   ww  w  .  ja v  a2  s.co  m*/
        assertEquals("This application can only be used after accepting the Terms of Use and Privacy Policy",
                driver.findElement(By.cssSelector("span")).getText());
        System.out.println("Rejected terms of use warning text correct");
    } catch (Error e) {
        verificationErrors.append(e.toString());
    }
}

From source file:automation.CenturyLink.java

@Test
public void test() throws Exception {
    driver.get(baseUrl + "/PtapRpts/Public/BackboneReport.aspx");
    driver.findElement(By.id("ctl00_ContentPlaceHolder1_LookingGlassBtn")).click();
    waitForText("body", "From");

    new Select(driver
            .findElement(By.id("ctl00_ContentPlaceHolder1_BackboneActiveTestControl_ActiveTestOriginDdl")))
                    .selectByVisibleText(locVar);
    //      driver.findElement(By.cssSelector("option[title=\"NORTH AMERICA: USA - AZ, TEMPE (PHX)\"]")).click();
    waitForText("body", "Test");

    //      new Select(driver.findElement(By.id("ctl00_ContentPlaceHolder1_BackboneActiveTestControl_TestDdl"))).selectByVisibleText("TRACE");
    driver.findElement(By.cssSelector("option[value=\"TRACE\"]")).click();
    driver.findElement(By.id("ctl00_ContentPlaceHolder1_BackboneActiveTestControl_OtherRadBtn")).click();
    waitForText("body", "Enter DNS");

    //      new Select(driver.findElement(By.id("ctl00_ContentPlaceHolder1_BackboneActiveTestControl_OtherDestFormatDdl"))).selectByVisibleText("IPv4");
    driver.findElement(By.cssSelector("option[value=\"IPv4\"]")).click();
    waitForText("body", "Enter IP");

    driver.findElement(By.id("ctl00_ContentPlaceHolder1_BackboneActiveTestControl_DestTxb")).clear();
    driver.findElement(By.id("ctl00_ContentPlaceHolder1_BackboneActiveTestControl_DestTxb")).sendKeys(dstIP);
    driver.findElement(By.id("ctl00_ContentPlaceHolder1_BackboneActiveTestControl_RunTestBtn")).click();

}

From source file:automation.HE.java

@Test
public void test() throws Exception {
    driver.get(baseUrl + "/");

    if (driver.findElement(By.id("routers_core1.fmt1.he.net")).isSelected()) {
        driver.findElement(By.id("routers_core1.fmt1.he.net"))
                .click(); /* Seems to be the selected by default */

    }/*from w  ww. j  a  v a  2s  .c o m*/
    if (driver.findElement(By.id("routers_core1.fmt2.he.net")).isSelected()) {
        driver.findElement(By.id("routers_core1.fmt2.he.net"))
                .click(); /* Seems to be the selected by default */

    }

    driver.findElement(By.id(locVar)).click();
    driver.findElement(By.id("command_traceroute")).click();
    driver.findElement(By.id("ip")).clear();
    driver.findElement(By.id("ip")).sendKeys(dstIP);

    if (driver.findElement(By.id("raw")).isSelected()) {
        driver.findElement(By.id("raw")).click();
    }

    driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
}

From source file:automation.HE.java

@After
public void tearDown() throws Exception {
    try {// w w w .  ja v a  2  s  .c  om
        //         result = driver.findElement(By.cssSelector(cssSelector)).getAttribute("innerHTML");
        result = "";
        WebElement table = driver.findElement(By.cssSelector(cssSelector));
        //         System.out.println("1" + table.getAttribute("innerHTML"));
        //         System.out.println("table:" + table.html());
        List<WebElement> rows = table.findElements(By.tagName("tr"));
        //         System.out.println("2");
        for (WebElement row : rows) {
            for (WebElement cell : row.findElements(By.tagName("td"))) {
                result += cell.getText().trim() + "\t";
            }
            result += "\n";
            //            System.out.println(result);
            //            System.out.println("------");
        }
        System.out.println(result);

    } catch (Exception e) {
        Logger.getLogger(BT.class.getName()).log(Level.SEVERE, null, e);
    } finally {

        super.store();

        driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
            fail(verificationErrorString);
        }
    }
}

From source file:automation.Launcher.java

public void waitForText(String locator, String elementText) {
    boolean feedBack = driver.findElement(By.cssSelector(locator)).getText().contains(elementText);
    long beginWaitingTime = new Date().getTime();
    long timeToWait = 30;
    /* 3 seconds to wait, there should be a function to wait in selenium.. */

    while (!feedBack) {
        feedBack = driver.findElement(By.cssSelector(locator)).getText().contains(elementText);
        System.out.println(elementText + " " + feedBack);
        if (new Date().getTime() - beginWaitingTime > timeToWait) {
            break;
        }//from  w w w. j  a v a2s.  com
    }
    try {
        Thread.sleep(1 * 1000);
    } catch (InterruptedException ex) {
        Logger.getLogger(CenturyLink.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:automation.Zayo.java

@After
public void tearDown() throws Exception {
    try {//  ww w .  j  a v  a 2s .com
        result = driver.findElement(By.cssSelector(cssSelector)).getAttribute("innerHTML");
    } catch (Exception e) {
        Logger.getLogger(Peer1.class.getName()).log(Level.SEVERE, null, e);
    } finally {

        super.store();

        driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
            fail(verificationErrorString);
        }
    }
}

From source file:beseenium.model.action.findElementsBy.FindElementsByCss.java

License:Open Source License

/**
 * performs the find elements by css action.
 * @param n the index of the element to find information on, i.e. if 3 results are found
 * the 0 will be the first element 1 the second and so on. will get an array out of bounds.
 * If you wish the action to return all of the results found then set n = -1.
 * @return String representation of the returnParam set in the ActionData object
 * passed into the constructor./*  www . j  a v  a 2  s .com*/
 * @throws ActionDataException  
 */
@Override
public String execute(int n) throws ActionDataException {
    String searchParam = super.context.getInputParam();
    WebDriver browser = super.context.getDriver();
    List<WebElement> htmlElements = browser.findElements(By.cssSelector(searchParam));

    super.context.setElement(htmlElements);

    return FormatOutput.formatFindElementOutput(htmlElements, n);
}