Example usage for org.openqa.selenium By className

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

Introduction

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

Prototype

public static By className(String className) 

Source Link

Document

Find elements based on the value of the "class" attribute.

Usage

From source file:com.ibm.watson.app.qaclassifier.selenium.MenuMobileIT.java

License:Open Source License

@Test
public void clickOnMenuOptionRedirectsPage() throws InterruptedException {
    WebElement menuIconImg = driver.findElement(By.className("menuIconImg"));
    WebElement menuList = driver.findElement(By.className("menu-list"));
    assertTrue("Menu Icon is displayed", menuIconImg.isDisplayed());
    // Click the menu icon, it should show the menu list
    menuIconImg.click();/*from  www  . j a va 2 s  .  c  om*/

    // Unclear exactly why this is required.
    // Without this delay the findElements call might return less than the expected number of elements,
    // or some of the elements might not have any text.
    Thread.sleep(1000);

    //Get list of menu options
    List<WebElement> menuOptions = menuList.findElements(By.xpath(".//ul/li"));
    assertThat("Expect four menu options", menuOptions, hasSize(4));

    int menuIndex = 1;
    WebElement documentationOption = menuOptions.get(menuIndex); // "Documentation" option that will redirect to different page
    assertThat("Unexpected text for item at position " + menuIndex, documentationOption.getText(),
            is("Documentation"));
    documentationOption.click();

    //New tab with documentation is opened
    CommonFunctions.switchTabs(driver);
    assertThat("After clicking on the menu option, page is redirected", driver.getTitle(),
            is("Natural Language Classifier service documentation | Watson Developer Cloud"));
    driver.close();
}

From source file:com.ibm.watson.app.qaclassifier.selenium.WelcomePageIT.java

License:Open Source License

@Test
public void pressingNextButtonDynamic() throws InterruptedException {

    WebElement screenText = driver.findElement(By.id("screenText"));
    WebElement trainMeText = driver.findElement(By.id("trainMeText"));
    WebElement actionButton = driver.findElement(By.id("actionButton"));

    assertEquals("Proper welcome text is displayed.",
            "Hello! I'm Watson. I'm learning to answer questions about the Natural Language Classifier.",
            screenText.getText().replaceAll("\\s+", " "));

    assertEquals("Proper train me text is displayed.", "Train me. Let me know whether I provide good answers.",
            trainMeText.getText().replaceAll("\\s+", " "));

    actionButton.click();//from ww w. j  a va 2s  .co m

    assertTrue("Home page loads after pressing next button second time",
            driver.findElements(By.className("home")).size() > 0);
}

From source file:com.ipinyou.webpage.abnormalwebpage.AbnormalAdvertiserPage.java

public static void create(WebDriver driver, AbnormalAdvertiserInfo adinfo, int a)
        throws NoSuchElementException {

    driver.findElement(By.className("resource-create-btn")).click();
    driver.findElement(By.id("advertiser.name")).sendKeys(adinfo.adname);
    driver.findElement(By.id("advertiser.registerName")).sendKeys(adinfo.registername);
    if (a == 1) {
        driver.findElement(By.id("advertiser.serviceFeeRate")).sendKeys(adinfo.servicefeerate);
    }/* ww w  .  j av  a2  s . c  o m*/
    //      driver.findElement(By.id("advertiser.selfService1")).click();
    //      driver.findElement(By.id("advertiser.selfService0")).click();
    Select industry = new Select(driver.findElement(By.name("advertiser.verticalTagId")));
    industry.selectByVisibleText(adinfo.industrytext);
    WebElement websuite = driver.findElement(By.id("advertiser.website"));
    websuite.clear();
    websuite.sendKeys(adinfo.advertiserwebsite);
    driver.findElement(By.id("advertiser.cellphone")).sendKeys(adinfo.cellphone);
    driver.findElement(By.id("advertiser.contactName")).sendKeys(adinfo.contactname);
    driver.findElement(By.id("advertiser.email")).sendKeys(adinfo.email);
    driver.findElement(By.id("advertiser.showLogo1")).click();
    driver.findElement(By.id("advertiser.showLogo0")).click();
    WebElement addaptitude = driver.findElement(By.id("addQualificationFiles"));
    addaptitude.click();
    if (a == 2) {
        addaptitude.click();
    } else {
        ;
    }
    //ICP
    Select aptitudeicp = new Select(driver.findElement(By.name("types")));
    aptitudeicp.selectByValue("ICP");
    driver.findElement(By.name("qualifications")).sendKeys(adinfo.path);
    addaptitude.click();
    //
    Select aptitudelicense = new Select(driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[12]/td[2]/select")));
    aptitudelicense.selectByValue("License");
    WebElement chooselicense = driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[12]/td[2]/input"));
    chooselicense.sendKeys(adinfo.path);
    addaptitude.click();
    //
    Select aptitudelegalid = new Select(driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[13]/td[2]/select")));
    aptitudelegalid.selectByValue("LegalId");
    WebElement chooselegalid = driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[13]/td[2]/input"));
    chooselegalid.sendKeys(adinfo.path);

    addaptitude.click();
    //
    Select aptitudeproduct = new Select(driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[14]/td[2]/select")));
    aptitudeproduct.selectByValue("Product");
    WebElement chooseproduct = driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[14]/td[2]/input"));
    chooseproduct.sendKeys(adinfo.path);

    addaptitude.click();
    //
    Select aptitudeother = new Select(driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[15]/td[2]/select")));
    aptitudeother.selectByValue("Other");
    WebElement chooseother = driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[15]/td[2]/input"));
    chooseother.sendKeys(adinfo.path);

    WebElement submit = driver.findElement(By.name("submitForm"));
    submit.click();
}

From source file:com.ipinyou.webpage.abnormalwebpage.AbnormalAdvertiserPageName.java

public static void create(WebDriver driver, AbnormalAdvertiserNameInfo aainfo, int a)
        throws NoSuchElementException {

    driver.findElement(By.className("resource-create-btn")).click();
    driver.findElement(By.id("advertiser.name")).sendKeys(aainfo.getAdname());
    driver.findElement(By.id("advertiser.registerName")).sendKeys(aainfo.getRegistername());
    if (a == 1) {
        driver.findElement(By.id("advertiser.serviceFeeRate")).sendKeys(aainfo.getServicefeerate());
    }/*  w  w  w . j av a 2 s .  c om*/
    //      driver.findElement(By.id("advertiser.selfService1")).click();
    //      driver.findElement(By.id("advertiser.selfService0")).click();
    Select industry = new Select(driver.findElement(By.name("advertiser.verticalTagId")));
    industry.selectByVisibleText(aainfo.getIndustrytext());
    WebElement websuite = driver.findElement(By.id("advertiser.website"));
    websuite.clear();
    websuite.sendKeys(aainfo.getAdvertiserwebsite());
    driver.findElement(By.id("advertiser.cellphone")).sendKeys(aainfo.getCellphone());
    driver.findElement(By.id("advertiser.contactName")).sendKeys(aainfo.getContactname());
    driver.findElement(By.id("advertiser.email")).sendKeys(aainfo.getEmail());
    driver.findElement(By.id("advertiser.showLogo1")).click();
    driver.findElement(By.id("advertiser.showLogo0")).click();
    WebElement addaptitude = driver.findElement(By.id("addQualificationFiles"));
    addaptitude.click();
    if (a == 2) {
        addaptitude.click();
    } else {
        ;
    }
    //ICP
    Select aptitudeicp = new Select(driver.findElement(By.name("types")));
    aptitudeicp.selectByValue("ICP");
    driver.findElement(By.name("qualifications")).sendKeys(aainfo.getPath());
    addaptitude.click();
    /*//
    Select aptitudelicense = new Select(driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[12]/td[2]/select")));
    aptitudelicense.selectByValue("License");
    WebElement chooselicense = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[12]/td[2]/input"));
    //      chooselicense.sendKeys(aainfo.getPath());
    addaptitude.click();
    //
    Select aptitudelegalid = new Select(driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[13]/td[2]/select")));
    aptitudelegalid.selectByValue("LegalId");
    WebElement chooselegalid = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[13]/td[2]/input"));
    chooselegalid.sendKeys(aainfo.getPath());
            
    addaptitude.click();
    //
    Select aptitudeproduct = new Select(driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[14]/td[2]/select")));
    aptitudeproduct.selectByValue("Product");
    WebElement chooseproduct = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[14]/td[2]/input"));
    chooseproduct.sendKeys(aainfo.getPath());
            
    addaptitude.click();
      //
    Select aptitudeother = new Select(driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[15]/td[2]/select")));
    aptitudeother.selectByValue("Other");
    WebElement chooseother = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[15]/td[2]/input"));
    chooseother.sendKeys(aainfo.getPath());*/

    WebElement submit = driver.findElement(By.name("submitForm"));
    submit.click();
}

From source file:com.ipinyou.webpage.AdvertiserPage.java

public static void create(WebDriver driver, AdvertiserInfo adinfo, int a) throws NoSuchElementException {

    driver.findElement(By.className("resource-create-btn")).click();
    driver.findElement(By.id("advertiser.name")).sendKeys(adinfo.adname);
    driver.findElement(By.id("advertiser.registerName")).sendKeys(adinfo.registername);
    if (a == 1) {
        driver.findElement(By.id("advertiser.serviceFeeRate")).sendKeys(adinfo.servicefeerate);
    }/*from   ww w  . j  ava2s .c o  m*/
    //      driver.findElement(By.id("advertiser.selfService1")).click();
    //      driver.findElement(By.id("advertiser.selfService0")).click();
    Select industry = new Select(driver.findElement(By.name("advertiser.verticalTagId")));
    industry.selectByVisibleText(adinfo.industrytext);
    WebElement websuite = driver.findElement(By.id("advertiser.website"));
    websuite.clear();
    websuite.sendKeys(adinfo.advertiserwebsite);
    //4.0
    //      driver.findElement(By.id("advertiser.orgCodeNo")).sendKeys(adinfo.orgcodeno);
    driver.findElement(By.id("advertiser.cellphone")).sendKeys(adinfo.cellphone);
    driver.findElement(By.id("advertiser.contactName")).sendKeys(adinfo.contactname);
    driver.findElement(By.id("advertiser.type0")).click();
    driver.findElement(By.id("advertiser.email")).sendKeys(adinfo.email);
    driver.findElement(By.id("advertiser.showLogo1")).click();
    driver.findElement(By.id("advertiser.showLogo0")).click();
    WebElement addaptitude = driver.findElement(By.id("addQualificationFiles"));
    addaptitude.click();
    if (a == 2) {
        addaptitude.click();
        addaptitude.click();
    } else {
        ;
    }
    //ICP
    Select aptitudeicp = new Select(driver.findElement(By.name("types")));
    aptitudeicp.selectByValue("ICP");
    driver.findElement(By.name("qualifications")).sendKeys(adinfo.path);
    addaptitude.click();
    // 3.9
    Select aptitudelicense = new Select(driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[15]/td[2]/select")));
    aptitudelicense.selectByValue("License");
    WebElement chooselicense = driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[15]/td[2]/input"));
    chooselicense.sendKeys(adinfo.path);
    addaptitude.click();
    //
    Select aptitudelegalid = new Select(driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[16]/td[2]/select")));
    aptitudelegalid.selectByValue("LegalId");
    WebElement chooselegalid = driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[16]/td[2]/input"));
    chooselegalid.sendKeys(adinfo.path);

    addaptitude.click();
    //
    Select aptitudeproduct = new Select(driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[17]/td[2]/select")));
    aptitudeproduct.selectByValue("Product");
    WebElement chooseproduct = driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[17]/td[2]/input"));
    chooseproduct.sendKeys(adinfo.path);

    //
    addaptitude.click();
    Select aptitudeother = new Select(driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[18]/td[2]/select")));
    aptitudeother.selectByValue("Other");
    WebElement chooseother = driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[18]/td[2]/input"));
    chooseother.sendKeys(adinfo.path);

    //  4.0
    //
    /*Select aptitudelicense = new Select(driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[16]/td[2]/select")));
    aptitudelicense.selectByValue("License");
    WebElement chooselicense = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[16]/td[2]/input"));
    chooselicense.sendKeys(adinfo.path);
    addaptitude.click();
    //
    Select aptitudelegalid = new Select(driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[17]/td[2]/select")));
    aptitudelegalid.selectByValue("LegalId");
    WebElement chooselegalid = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[17]/td[2]/input"));
    chooselegalid.sendKeys(adinfo.path);
            
    addaptitude.click();
    //
    Select aptitudeproduct = new Select(driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[18]/td[2]/select")));
    aptitudeproduct.selectByValue("Product");
    WebElement chooseproduct = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[18]/td[2]/input"));
    chooseproduct.sendKeys(adinfo.path);
            
    addaptitude.click();
    //
    PubHandle.select(driver, By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[19]/td[2]/select"), "");
    WebElement orgen = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[19]/td[2]/input"));
    orgen.sendKeys(adinfo.path);
            
            
      //
    addaptitude.click();
    Select aptitudeother = new Select(driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[20]/td[2]/select")));
    aptitudeother.selectByValue("Other");
    WebElement chooseother = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[20]/td[2]/input"));
    chooseother.sendKeys(adinfo.path);*/

    if (a == 2) {
        driver.findElement(By.id("removeQ_1")).click();
        driver.findElement(By.id("removeQ_2")).click();
    } else {
        ;
    }

    WebElement submit = driver.findElement(By.name("submitForm"));
    submit.click();
}

From source file:com.ipinyou.webpage.del.DelAdvertiserPage.java

public static void create(WebDriver driver, AdvertiserInfo adinfo, int a) throws NoSuchElementException {

    driver.findElement(By.className("resource-create-btn")).click();
    driver.findElement(By.id("advertiser.name")).sendKeys(adinfo.adname);
    driver.findElement(By.id("advertiser.registerName")).sendKeys(adinfo.registername);
    if (a == 1) {
        driver.findElement(By.id("advertiser.serviceFeeRate")).sendKeys(adinfo.servicefeerate);
    }/*from   ww  w. j a  va  2 s. co m*/
    //      driver.findElement(By.id("advertiser.selfService1")).click();
    //      driver.findElement(By.id("advertiser.selfService0")).click();
    Select industry = new Select(driver.findElement(By.name("advertiser.verticalTagId")));
    industry.selectByVisibleText(adinfo.industrytext);
    WebElement websuite = driver.findElement(By.id("advertiser.website"));
    websuite.clear();
    websuite.sendKeys(adinfo.advertiserwebsite);
    driver.findElement(By.id("advertiser.cellphone")).sendKeys(adinfo.cellphone);
    driver.findElement(By.id("advertiser.contactName")).sendKeys(adinfo.contactname);
    driver.findElement(By.id("advertiser.type0")).click();
    driver.findElement(By.id("advertiser.email")).sendKeys(adinfo.email);
    driver.findElement(By.id("advertiser.showLogo1")).click();
    driver.findElement(By.id("advertiser.showLogo0")).click();
    WebElement addaptitude = driver.findElement(By.id("addQualificationFiles"));
    addaptitude.click();
    if (a == 2) {
        addaptitude.click();
    } else {
        ;
    }
    //ICP
    Select aptitudeicp = new Select(driver.findElement(By.name("types")));
    aptitudeicp.selectByValue("ICP");
    driver.findElement(By.name("qualifications")).sendKeys(adinfo.path);
    addaptitude.click();
    //
    Select aptitudelicense = new Select(driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[14]/td[2]/select")));
    aptitudelicense.selectByValue("License");
    WebElement chooselicense = driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[14]/td[2]/input"));
    chooselicense.sendKeys(adinfo.path);
    addaptitude.click();
    //
    Select aptitudelegalid = new Select(driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[15]/td[2]/select")));
    aptitudelegalid.selectByValue("LegalId");
    WebElement chooselegalid = driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[15]/td[2]/input"));
    chooselegalid.sendKeys(adinfo.path);

    addaptitude.click();
    //
    Select aptitudeproduct = new Select(driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[16]/td[2]/select")));
    aptitudeproduct.selectByValue("Product");
    WebElement chooseproduct = driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[16]/td[2]/input"));
    chooseproduct.sendKeys(adinfo.path);

    addaptitude.click();
    //
    Select aptitudeother = new Select(driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[17]/td[2]/select")));
    aptitudeother.selectByValue("Other");
    WebElement chooseother = driver
            .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[17]/td[2]/input"));
    chooseother.sendKeys(adinfo.path);

    WebElement submit = driver.findElement(By.name("submitForm"));
    submit.click();
}

From source file:com.ipinyou.webpage.del.DelAdvertiserPage.java

public static void delAdvertiser(WebDriver driver, AdvertiserInfo adinfo) throws InterruptedException {
    driver.findElement(By.id("adAdminMenu")).click();
    driver.findElement(By.id("appendedInputButton")).clear();
    driver.findElement(By.id("appendedInputButton")).sendKeys(adinfo.getDeladname());
    driver.findElement(By.xpath("//*[@id='queryForm']/button")).click();
    boolean flag = Check.elementexist(driver, By.linkText(adinfo.getDeladname()), 5, adinfo.getDeladname());
    if (flag) {/*from  ww w .j a  va 2s.  co  m*/
        driver.findElement(By.className("dele-icon")).click();
        driver.findElement(By.className("confirm")).click();
    } else {
        ScreenshotandAssert.screenandasserttext(driver, "" + adinfo.getDeladname(),
                adinfo.getDeladname(), By.linkText(adinfo.getDeladname()));
    }
}

From source file:com.itson.servicedesigncenter.SdcPages.java

License:Open Source License

public boolean networkGroupExists(String groupName, String page) {
    long start = browser.timer_restart();
    setTopNavLink(page);/*from   w  ww  . j  a  v a  2  s  . c  om*/
    setSearchfield(groupName);
    Collection c = browser.findElements(By.className("dataTables_empty"));
    return c.size() > 0;
}

From source file:com.itson.servicedesigncenter.SdcPages.java

License:Open Source License

public SdcPages verifyGroupDeleted(String groupName, String page) {
    browser.logAction("Verify Deleted " + page + " Named: " + groupName);
    setTopNavLink(page);//from w  ww.  j a  va  2 s  .co  m
    setSearchfield(groupName);
    browser.sleep(5000);
    //browser.visibilityOfElementLocated(By.className("dataTables_empty"));
    browser.retryingElement(By.className("dataTables_empty"));
    return this;
}

From source file:com.itson.servicedesigncenter.SdcPages.java

License:Open Source License

public SdcPages verifyNetworkGroup(String groupName) {
    setUnlockNetwork();/*  ww w.ja  v a 2s  .  co m*/
    verifyGroupName(groupName);
    String liveTagName = browser.findElement(By.className("tag-item")).getText();
    browser.logAction("****got tag  " + liveTagName);
    browser.compareText(liveTagName, networkCdmaNumber);
    // String liveMccName = browser.findElement(By.cssSelector("div.control-group:nth-child(4) > div:nth-child(2) > tags-input:nth-child(1) > div:nth-child(1) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(1) > span:nth-child(1)")).getText();
    // browser.logAction("****got mcc  " + liveMccName);
    //browser.compareText(liveMccName, networkMccMnc);

    setGroupCancelBtn();
    return this;
}