Example usage for org.openqa.selenium By name

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

Introduction

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

Prototype

public static By name(String name) 

Source Link

Usage

From source file:com.consol.citrus.selenium.client.WebClient.java

License:Apache License

/**
 * Set a value on a single input element by its name.
 *
 * @param name name to set./*from  w ww . j  a va 2s  .com*/
 * @param value Value to set.
 */
public void setInputByName(String name, String value) {
    findElement(By.name(name)).clear();
    findElement(By.name(name)).sendKeys(value);
}

From source file:com.continuuity.test.pagetest.CreateServiceTest.java

License:Apache License

@Test
public void test_01_submitHadoopHdfsDatanode() throws Exception {
    globalDriver.get(Constants.SERVICE_CREATE_URI);
    Service service = EXAMPLE_READER.getServices(Constants.SERVICES_PATH).get("hadoop-hdfs-datanode");
    WebElement inputName = globalDriver.findElement(By.name("inputName"));
    inputName.sendKeys(service.getName());
    WebElement inputDescription = globalDriver.findElement(By.cssSelector("#inputDescription"));
    inputDescription.sendKeys(service.getDescription());

    Select dependsOn = new Select(globalDriver.findElement(By.cssSelector("#inputRuntimeRequires")));
    WebElement addService = globalDriver.findElement(By.cssSelector("#add-service"));
    dependsOn.selectByVisibleText("base");
    addService.click();/*ww  w .ja va2  s  .c om*/

    dependsOn.selectByVisibleText("hadoop-hdfs-namenode");
    addService.click();

    WebElement addAction = globalDriver.findElement(By.cssSelector("#add-action"));
    addAction.click();
    addAction.click();
    addAction.click();
    addAction.click();

    List<WebElement> actionEntries = globalDriver.findElements(By.cssSelector(".action-entry"));

    actionEntries.get(0).findElement(By.cssSelector(".inputCategory")).sendKeys("install");
    actionEntries.get(0).findElement(By.cssSelector(".inputType")).sendKeys("chef-solo");
    actionEntries.get(0).findElement(By.name("run_list")).sendKeys(
            service.getProvisionerActions().get(ProvisionerAction.INSTALL).getFields().get("run_list"));
    String data = service.getProvisionerActions().get(ProvisionerAction.INSTALL).getFields()
            .get("json_attributes");
    if (data != null) {
        actionEntries.get(0).findElement(By.name("json_attributes")).sendKeys(data);
    }

    actionEntries.get(1).findElement(By.cssSelector(".inputCategory")).sendKeys("configure");
    actionEntries.get(1).findElement(By.cssSelector(".inputType")).sendKeys("chef-solo");
    actionEntries.get(1).findElement(By.name("run_list")).sendKeys(
            service.getProvisionerActions().get(ProvisionerAction.CONFIGURE).getFields().get("run_list"));
    data = service.getProvisionerActions().get(ProvisionerAction.CONFIGURE).getFields().get("json_attributes");
    if (data != null) {
        actionEntries.get(1).findElement(By.name("json_attributes")).sendKeys(data);
    }

    actionEntries.get(2).findElement(By.cssSelector(".inputCategory")).sendKeys("start");
    actionEntries.get(2).findElement(By.cssSelector(".inputType")).sendKeys("chef-solo");
    actionEntries.get(2).findElement(By.name("run_list"))
            .sendKeys(service.getProvisionerActions().get(ProvisionerAction.START).getFields().get("run_list"));
    data = service.getProvisionerActions().get(ProvisionerAction.START).getFields().get("json_attributes");
    if (data != null) {
        actionEntries.get(2).findElement(By.name("json_attributes")).sendKeys(data);
    }

    actionEntries.get(3).findElement(By.cssSelector(".inputCategory")).sendKeys("stop");
    actionEntries.get(3).findElement(By.cssSelector(".inputType")).sendKeys("chef-solo");
    actionEntries.get(3).findElement(By.name("run_list"))
            .sendKeys(service.getProvisionerActions().get(ProvisionerAction.STOP).getFields().get("run_list"));
    data = service.getProvisionerActions().get(ProvisionerAction.STOP).getFields().get("json_attributes");
    if (data != null) {
        actionEntries.get(3).findElement(By.name("json_attributes")).sendKeys(data);
    }

    globalDriver.findElement(By.cssSelector("#create-service-form")).submit();
    Global.driverWait(1);
    assertEquals(Constants.SERVICES_URL, globalDriver.getCurrentUrl());
}

From source file:com.continuuity.test.pagetest.CreateServiceTest.java

License:Apache License

@Test
public void test_02_submitServiceError() throws Exception {
    globalDriver.get(Constants.SERVICE_CREATE_URI);
    assertFalse(globalDriver.findElement(By.cssSelector("#notification")).isDisplayed());
    WebElement inputName = globalDriver.findElement(By.name("inputName"));
    inputName.sendKeys("asdf");
    WebElement inputDescription = globalDriver.findElement(By.cssSelector("#inputDescription"));
    inputDescription.sendKeys("asdf");
    globalDriver.findElement(By.cssSelector("#create-service-form")).submit();
    assertTrue(globalDriver.findElement(By.cssSelector("#notification")).isDisplayed());
}

From source file:com.crawljax.plugins.testilizer.generated.photogallery_EXND.GeneratedTestCase40.java

@Test
public void method40() {
    driver.get(url);/*from   ww w  . j a v  a 2s . com*/
    //From state 0 to state 1
    //Eventable{eventType=click, identification=text Admin Page, element=Element{node=[A: null], tag=A, text=Admin Page, attributes={href=admin.php, title=Login to the Administration Region}}, source=StateVertexImpl{id=0, name=index}, target=StateVertexImpl{id=1, name=state1}}
    mutateDOMTree(0);
    checkState0_OriginalAssertions();
    checkState0_ReusedAssertions();
    checkState0_GeneratedAssertions();
    checkState0_LearnedAssertions();
    checkState0_AllAssertions();
    checkState0_RandAssertions1();
    checkState0_RandAssertions2();
    checkState0_RandAssertions3();
    checkState0_RandAssertions4();
    checkState0_RandAssertions5();
    driver.findElement(By.linkText("Admin Page")).click();
    //From state 1 to state 2
    //Eventable{eventType=click, identification=cssSelector input.submit, element=Element{node=[INPUT: null], tag=INPUT, text=, attributes={class=submit, type=submit, value=??????Login??????}}, source=StateVertexImpl{id=1, name=state1}, target=StateVertexImpl{id=2, name=state2}}
    mutateDOMTree(1);
    checkState1_OriginalAssertions();
    checkState1_ReusedAssertions();
    checkState1_GeneratedAssertions();
    checkState1_LearnedAssertions();
    checkState1_AllAssertions();
    checkState1_RandAssertions1();
    checkState1_RandAssertions2();
    checkState1_RandAssertions3();
    checkState1_RandAssertions4();
    checkState1_RandAssertions5();
    driver.findElement(By.id("loginAdminPass")).clear();
    driver.findElement(By.id("loginAdminPass")).sendKeys("editor");
    driver.findElement(By.cssSelector("input.submit")).click();
    //From state 2 to state 3
    //Eventable{eventType=click, identification=text Manage Stories, element=Element{node=[A: null], tag=A, text=Manage Stories, attributes={href=?page=stories}}, source=StateVertexImpl{id=2, name=state2}, target=StateVertexImpl{id=3, name=state3}}
    mutateDOMTree(2);
    checkState2_OriginalAssertions();
    checkState2_ReusedAssertions();
    checkState2_GeneratedAssertions();
    checkState2_LearnedAssertions();
    checkState2_AllAssertions();
    checkState2_RandAssertions1();
    checkState2_RandAssertions2();
    checkState2_RandAssertions3();
    checkState2_RandAssertions4();
    checkState2_RandAssertions5();
    driver.findElement(By.linkText("Manage Stories")).click();
    //From state 3 to state 4
    //Eventable{eventType=click, identification=cssSelector input.submit, element=Element{node=[INPUT: null], tag=INPUT, text=, attributes={class=submit, type=submit, value=??????Add Story??????}}, source=StateVertexImpl{id=3, name=state3}, target=StateVertexImpl{id=4, name=state4}}
    mutateDOMTree(3);
    checkState3_OriginalAssertions();
    checkState3_ReusedAssertions();
    checkState3_GeneratedAssertions();
    checkState3_LearnedAssertions();
    checkState3_AllAssertions();
    checkState3_RandAssertions1();
    checkState3_RandAssertions2();
    checkState3_RandAssertions3();
    checkState3_RandAssertions4();
    checkState3_RandAssertions5();
    driver.findElement(By.name("desc")).clear();
    driver.findElement(By.name("desc")).sendKeys("Greenery !!");
    driver.findElement(By.id("name")).clear();
    driver.findElement(By.id("name")).sendKeys("Photos");
    driver.findElement(By.cssSelector("input.submit")).click();
    //From state 4 to state 5
    //Eventable{eventType=click, identification=cssSelector a[title="Log Out"], element=Element{node=[A: null], tag=A, text=, attributes={href=?page=logout, title=Log Out}}, source=StateVertexImpl{id=4, name=state4}, target=StateVertexImpl{id=5, name=state5}}
    mutateDOMTree(4);
    checkState4_OriginalAssertions();
    checkState4_ReusedAssertions();
    checkState4_GeneratedAssertions();
    checkState4_LearnedAssertions();
    checkState4_AllAssertions();
    checkState4_RandAssertions1();
    checkState4_RandAssertions2();
    checkState4_RandAssertions3();
    checkState4_RandAssertions4();
    checkState4_RandAssertions5();
    driver.findElement(By.cssSelector("a[title=\"Log Out\"]")).click();
    //Sink node at state 5
    mutateDOMTree(5);
    checkState5_OriginalAssertions();
    checkState5_ReusedAssertions();
    checkState5_GeneratedAssertions();
    checkState5_LearnedAssertions();
    checkState5_AllAssertions();
    checkState5_RandAssertions1();
    checkState5_RandAssertions2();
    checkState5_RandAssertions3();
    checkState5_RandAssertions4();
    checkState5_RandAssertions5();
}

From source file:com.crawljax.plugins.testilizer.generated.photogallery_EXND.GeneratedTestCase6.java

@Test
public void method6() {
    driver.get(url);/*from w  w w  .j a v  a  2 s .  c o m*/
    //From state 0 to state 6
    //Eventable{eventType=click, identification=text Admin Page, element=Element{node=[A: null], tag=A, text=Admin Page, attributes={href=admin.php, title=Login to the Administration Region}}, source=StateVertexImpl{id=0, name=index}, target=StateVertexImpl{id=6, name=state6}}
    mutateDOMTree(0);
    checkState0_OriginalAssertions();
    checkState0_ReusedAssertions();
    checkState0_GeneratedAssertions();
    checkState0_LearnedAssertions();
    checkState0_AllAssertions();
    checkState0_RandAssertions1();
    checkState0_RandAssertions2();
    checkState0_RandAssertions3();
    checkState0_RandAssertions4();
    checkState0_RandAssertions5();
    driver.findElement(By.linkText("Admin Page")).click();
    //From state 6 to state 7
    //Eventable{eventType=click, identification=cssSelector input.submit, element=Element{node=[INPUT: null], tag=INPUT, text=, attributes={class=submit, type=submit, value=??????Login??????}}, source=StateVertexImpl{id=6, name=state6}, target=StateVertexImpl{id=7, name=state7}}
    mutateDOMTree(6);
    checkState6_OriginalAssertions();
    checkState6_ReusedAssertions();
    checkState6_GeneratedAssertions();
    checkState6_LearnedAssertions();
    checkState6_AllAssertions();
    checkState6_RandAssertions1();
    checkState6_RandAssertions2();
    checkState6_RandAssertions3();
    checkState6_RandAssertions4();
    checkState6_RandAssertions5();
    driver.findElement(By.id("loginAdminPass")).clear();
    driver.findElement(By.id("loginAdminPass")).sendKeys("editor");
    driver.findElement(By.cssSelector("input.submit")).click();
    //From state 7 to state 8
    //Eventable{eventType=click, identification=text Manage Categories, element=Element{node=[A: null], tag=A, text=Manage Categories, attributes={href=?page=categories}}, source=StateVertexImpl{id=7, name=state7}, target=StateVertexImpl{id=8, name=state8}}
    mutateDOMTree(7);
    checkState7_OriginalAssertions();
    checkState7_ReusedAssertions();
    checkState7_GeneratedAssertions();
    checkState7_LearnedAssertions();
    checkState7_AllAssertions();
    checkState7_RandAssertions1();
    checkState7_RandAssertions2();
    checkState7_RandAssertions3();
    checkState7_RandAssertions4();
    checkState7_RandAssertions5();
    driver.findElement(By.linkText("Manage Categories")).click();
    //From state 8 to state 11
    //Eventable{eventType=click, identification=cssSelector input.submit, element=Element{node=[INPUT: null], tag=INPUT, text=, attributes={class=submit, type=submit, value=??????Add Category??????}}, source=StateVertexImpl{id=8, name=state8}, target=StateVertexImpl{id=11, name=state11}}
    mutateDOMTree(8);
    checkState8_OriginalAssertions();
    checkState8_ReusedAssertions();
    checkState8_GeneratedAssertions();
    checkState8_LearnedAssertions();
    checkState8_AllAssertions();
    checkState8_RandAssertions1();
    checkState8_RandAssertions2();
    checkState8_RandAssertions3();
    checkState8_RandAssertions4();
    checkState8_RandAssertions5();
    driver.findElement(By.name("desc")).clear();
    driver.findElement(By.name("desc")).sendKeys("contains photos of all the flowers !");
    driver.findElement(By.id("name")).clear();
    driver.findElement(By.id("name")).sendKeys("flowers");
    driver.findElement(By.cssSelector("input.submit")).click();
    //From state 11 to state 12
    //Eventable{eventType=click, identification=cssSelector a[title="Log Out"], element=Element{node=[A: null], tag=A, text=, attributes={href=?page=logout, title=Log Out}}, source=StateVertexImpl{id=11, name=state11}, target=StateVertexImpl{id=12, name=state12}}
    mutateDOMTree(11);
    checkState11_OriginalAssertions();
    checkState11_ReusedAssertions();
    checkState11_GeneratedAssertions();
    checkState11_LearnedAssertions();
    checkState11_AllAssertions();
    checkState11_RandAssertions1();
    checkState11_RandAssertions2();
    checkState11_RandAssertions3();
    checkState11_RandAssertions4();
    checkState11_RandAssertions5();
    driver.findElement(By.cssSelector("a[title=\"Log Out\"]")).click();
    //Sink node at state 12
    mutateDOMTree(12);
    checkState12_OriginalAssertions();
    checkState12_ReusedAssertions();
    checkState12_GeneratedAssertions();
    checkState12_LearnedAssertions();
    checkState12_AllAssertions();
    checkState12_RandAssertions1();
    checkState12_RandAssertions2();
    checkState12_RandAssertions3();
    checkState12_RandAssertions4();
    checkState12_RandAssertions5();
}

From source file:com.crawljax.plugins.testilizer.generated.photogallery_EXND.GeneratedTestCase9.java

@Test
public void method9() {
    driver.get(url);//  w w w .ja v  a  2  s.co m
    //From state 0 to state 13
    //Eventable{eventType=click, identification=text Admin Page, element=Element{node=[A: null], tag=A, text=Admin Page, attributes={href=admin.php, title=Login to the Administration Region}}, source=StateVertexImpl{id=0, name=index}, target=StateVertexImpl{id=13, name=state13}}
    mutateDOMTree(0);
    checkState0_OriginalAssertions();
    checkState0_ReusedAssertions();
    checkState0_GeneratedAssertions();
    checkState0_LearnedAssertions();
    checkState0_AllAssertions();
    checkState0_RandAssertions1();
    checkState0_RandAssertions2();
    checkState0_RandAssertions3();
    checkState0_RandAssertions4();
    checkState0_RandAssertions5();
    driver.findElement(By.linkText("Admin Page")).click();
    //From state 13 to state 14
    //Eventable{eventType=click, identification=cssSelector input.submit, element=Element{node=[INPUT: null], tag=INPUT, text=, attributes={class=submit, type=submit, value=??????Login??????}}, source=StateVertexImpl{id=13, name=state13}, target=StateVertexImpl{id=14, name=state14}}
    mutateDOMTree(13);
    checkState13_OriginalAssertions();
    checkState13_ReusedAssertions();
    checkState13_GeneratedAssertions();
    checkState13_LearnedAssertions();
    checkState13_AllAssertions();
    checkState13_RandAssertions1();
    checkState13_RandAssertions2();
    checkState13_RandAssertions3();
    checkState13_RandAssertions4();
    checkState13_RandAssertions5();
    driver.findElement(By.id("loginAdminPass")).clear();
    driver.findElement(By.id("loginAdminPass")).sendKeys("editor");
    driver.findElement(By.cssSelector("input.submit")).click();
    //From state 14 to state 8
    //Eventable{eventType=click, identification=text Manage Categories, element=Element{node=[A: null], tag=A, text=Manage Categories, attributes={href=?page=categories}}, source=StateVertexImpl{id=14, name=state14}, target=StateVertexImpl{id=8, name=state8}}
    mutateDOMTree(14);
    checkState14_OriginalAssertions();
    checkState14_ReusedAssertions();
    checkState14_GeneratedAssertions();
    checkState14_LearnedAssertions();
    checkState14_AllAssertions();
    checkState14_RandAssertions1();
    checkState14_RandAssertions2();
    checkState14_RandAssertions3();
    checkState14_RandAssertions4();
    checkState14_RandAssertions5();
    driver.findElement(By.linkText("Manage Categories")).click();
    //From state 8 to state 11
    //Eventable{eventType=click, identification=cssSelector input.submit, element=Element{node=[INPUT: null], tag=INPUT, text=, attributes={class=submit, type=submit, value=??????Add Category??????}}, source=StateVertexImpl{id=8, name=state8}, target=StateVertexImpl{id=11, name=state11}}
    mutateDOMTree(8);
    checkState8_OriginalAssertions();
    checkState8_ReusedAssertions();
    checkState8_GeneratedAssertions();
    checkState8_LearnedAssertions();
    checkState8_AllAssertions();
    checkState8_RandAssertions1();
    checkState8_RandAssertions2();
    checkState8_RandAssertions3();
    checkState8_RandAssertions4();
    checkState8_RandAssertions5();
    driver.findElement(By.name("desc")).clear();
    driver.findElement(By.name("desc")).sendKeys("contains photos of all the flowers !");
    driver.findElement(By.id("name")).clear();
    driver.findElement(By.id("name")).sendKeys("flowers");
    driver.findElement(By.cssSelector("input.submit")).click();
    //From state 11 to state 19
    //Eventable{eventType=click, identification=xpath (//a[contains(text(),'Delete / Clear')])[2], element=Element{node=[A: null], tag=A, text=Delete / Clear, attributes={href=?page=categories&cmd=doDel&cid=2}}, source=StateVertexImpl{id=11, name=state11}, target=StateVertexImpl{id=19, name=state19}}
    mutateDOMTree(11);
    checkState11_OriginalAssertions();
    checkState11_ReusedAssertions();
    checkState11_GeneratedAssertions();
    checkState11_LearnedAssertions();
    checkState11_AllAssertions();
    checkState11_RandAssertions1();
    checkState11_RandAssertions2();
    checkState11_RandAssertions3();
    checkState11_RandAssertions4();
    checkState11_RandAssertions5();
    driver.findElement(By.xpath("(//a[contains(text(),'Delete / Clear')])[2]")).click();
    //From state 19 to state 21
    //Eventable{eventType=click, identification=cssSelector input.submit, element=Element{node=[INPUT: null], tag=INPUT, text=, attributes={class=submit, type=submit, value=??????Delete it!??????}}, source=StateVertexImpl{id=19, name=state19}, target=StateVertexImpl{id=21, name=state21}}
    mutateDOMTree(19);
    checkState19_OriginalAssertions();
    checkState19_ReusedAssertions();
    checkState19_GeneratedAssertions();
    checkState19_LearnedAssertions();
    checkState19_AllAssertions();
    checkState19_RandAssertions1();
    checkState19_RandAssertions2();
    checkState19_RandAssertions3();
    checkState19_RandAssertions4();
    checkState19_RandAssertions5();
    driver.findElement(By.cssSelector("input.submit")).click();
    //From state 21 to state 22
    //Eventable{eventType=click, identification=cssSelector a[title="Log Out"], element=Element{node=[A: null], tag=A, text=, attributes={href=?page=logout, title=Log Out}}, source=StateVertexImpl{id=21, name=state21}, target=StateVertexImpl{id=22, name=state22}}
    mutateDOMTree(21);
    checkState21_OriginalAssertions();
    checkState21_ReusedAssertions();
    checkState21_GeneratedAssertions();
    checkState21_LearnedAssertions();
    checkState21_AllAssertions();
    checkState21_RandAssertions1();
    checkState21_RandAssertions2();
    checkState21_RandAssertions3();
    checkState21_RandAssertions4();
    checkState21_RandAssertions5();
    driver.findElement(By.cssSelector("a[title=\"Log Out\"]")).click();
    //Sink node at state 22
    mutateDOMTree(22);
    checkState22_OriginalAssertions();
    checkState22_ReusedAssertions();
    checkState22_GeneratedAssertions();
    checkState22_LearnedAssertions();
    checkState22_AllAssertions();
    checkState22_RandAssertions1();
    checkState22_RandAssertions2();
    checkState22_RandAssertions3();
    checkState22_RandAssertions4();
    checkState22_RandAssertions5();
}

From source file:com.dhenton9000.selenium.generic.GenericAutomationRepository.java

/**
 * generate the By selector//from w  ww.j  av a  2 s. c  om
 *
 * @param selectorChoice the desired selector, eg by css Selector
 * @param selectorValue the string to search for
 * @return the By element
 */
public static By generateSelectorBy(SELECTOR_CHOICE selectorChoice, String selectorValue) {
    By selectorBy = null;

    switch (selectorChoice) {
    case id:
        selectorBy = By.id(selectorValue);
        break;
    case name:
        selectorBy = By.name(selectorValue);
        break;
    case className:
        selectorBy = By.className(selectorValue);
        break;
    case linkText:
        selectorBy = By.linkText(selectorValue);
        break;
    case xpath:
        selectorBy = By.xpath(selectorValue);
        break;
    case tagName:
        selectorBy = By.tagName(selectorValue);
        break;
    case cssSelector:
        selectorBy = By.cssSelector(selectorValue);
        break;
    case partialLinkText:
        selectorBy = By.partialLinkText(selectorValue);
        break;
    case wicketPathMatch:
        selectorBy = WicketBy.wicketPathMatch(selectorValue);
        break;
    case wicketPathContains:
        selectorBy = WicketBy.wicketPathContains(selectorValue);
        break;
    default:
        throw new AssertionError("unable to match selector " + selectorChoice.name());
    }

    return selectorBy;
}

From source file:com.digi.selenium.util.common.PageNavigation.java

/**
 * Handle input Textfield['Text'] on page by element ID
 * pass the input data //  w w  w  . j  a  va  2 s  .  c o  m
 * @param Wedriver localWebDeriver  
 * @param String elementID
 * @param String inputData
 * @throws Exception 
 */

protected void handleClearInputField_ByName(String elementID) {
    // try{

    getDriver().findElement(By.name(elementID)).clear();

    /*}catch(Exception e) {
       //System.out.println("Fail : Element ID '" + elementID + " Not Found");
       log.error("Fail : Element ID '" + elementID + " Not Found");
       throw(e);
    }*/
}

From source file:com.digi.selenium.util.common.PageNavigation.java

/**
 * Handle input Textfield['Text'] on page by element Name
 * pass the input data //w ww  . j  a  v  a2 s  .c o m
 * @param Wedriver localWebDeriver  
 * @param String elementID
 * @param String inputData
 * @throws Exception 
 */

protected void handleInputField_ByName(String elementName, String inputData) {
    // try{
    getDriver().findElement(By.name(elementName)).sendKeys(inputData);
    /*}catch(Exception e) {
       //System.out.println("Fail : Element '" + elementName + " Not Found");
       log.error("Fail : Element '" + elementName + " Not Found");
       throw(e);
       //e.printStackTrace();
       //System.exit(0);
    }*/
}

From source file:com.digi.selenium.util.common.PageNavigation.java

/**
 * Handle the click action on button by button Name
 * @param Wedriver webDeriver  /*from www  .  j  av a2  s.  c o m*/
 * @param String elementName
 * 
 */

protected void handleButtonClick_ByName(String elementName) {
    try {
        getDriver().findElement(By.name(elementName)).click();
    } catch (Exception e) {
        //System.out.println("Fail : Element Name'" + elementName + "' Click action Failed");
        log.error("Fail : Element Name'" + elementName + "' Click action Failed");
    }
}