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.formkiq.web.WorkflowEditorControllerIntegrationTest.java

License:Apache License

/**
 * testAddWorkflow16().//w  w w. j  a  va 2  s  . c o m
 * change workflow name.
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow16() throws Exception {
    // given

    // when - add step
    clickAddNewWorkflow();

    findElementBy(By.id("tab_s1e1")).click();

    getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("fieldeditorform")));

    findElementBy(By.name("name")).clear();
    findElementBy(By.name("name")).sendKeys("samplewf");
    findElementBy(By.name("21")).click();
    //findElementBy(By.className("form-modal-update-button")).click();
    click(By.name("_eventId_next"));

    // then
    getWait().until(ExpectedConditions.invisibilityOfElementLocated(By.id("fieldeditorform")));

    assertEquals("samplewf", findElementBy(By.id("tab_s1e1")).getText());

    findElementBy(By.id("tab_s1e1")).click();

    getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("fieldeditorform")));
    assertEquals("samplewf", findElementBy(By.name("name")).getAttribute("value"));

    assertTrue(findElementBy(By.name("21")).isSelected());
}

From source file:com.formkiq.web.WorkflowEditorControllerIntegrationTest.java

License:Apache License

/**
 * testAddWorkflow17().//  ww  w. j  ava  2 s .c o  m
 * change form name & step / print steps order.
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow17() throws Exception {
    // given
    String stepsSel = "#steps_table tbody > tr";
    String printstepsSel = "#printsteps_table tbody > tr";

    // when - add step
    clickAddNewWorkflow();

    addBlankForm();

    findElementBy(By.id("tab_s1e2")).click();

    getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("fieldeditorform")));

    findElementBy(By.name("name")).sendKeys("samplewf");
    //findElementBy(By.className("form-modal-update-button")).click();
    click(By.name("_eventId_next"));

    // then
    getWait().until(ExpectedConditions.invisibilityOfElementLocated(By.id("fieldeditorform")));

    assertTrue(findElementBy(By.id("tab_s1e2")).getText().endsWith("New Formsamplewf"));

    addBlankForm();

    findElementBy(By.id("tab_s1e1")).click();

    // then
    assertRowEquals(findElements(By.cssSelector(stepsSel)),
            Arrays.asList("Form Name", "New Formsamplewf", "New Form"));
    assertRowEquals(findElements(By.cssSelector(printstepsSel)),
            Arrays.asList("Form Name", "New Formsamplewf", "New Form"));

    // when
    findElementBy(By.id("stepup_0")).click();
    findElementBy(By.id("printstepup_0")).click();

    // then
    assertRowEquals(findElements(By.cssSelector(stepsSel)),
            Arrays.asList("Form Name", "New Formsamplewf", "New Form"));
    assertRowEquals(findElements(By.cssSelector(printstepsSel)),
            Arrays.asList("Form Name", "New Formsamplewf", "New Form"));

    // when
    findElementBy(By.id("stepup_1")).click();
    findElementBy(By.id("printstepup_1")).click();

    // then
    assertRowEquals(findElements(By.cssSelector(stepsSel)),
            Arrays.asList("Form Name", "New Form", "New Formsamplewf"));
    assertRowEquals(findElements(By.cssSelector(printstepsSel)),
            Arrays.asList("Form Name", "New Form", "New Formsamplewf"));

    // when
    findElementBy(By.id("stepdown_0")).click();
    findElementBy(By.id("printstepdown_0")).click();

    // then
    assertRowEquals(findElements(By.cssSelector(stepsSel)),
            Arrays.asList("Form Name", "New Formsamplewf", "New Form"));
    assertRowEquals(findElements(By.cssSelector(printstepsSel)),
            Arrays.asList("Form Name", "New Formsamplewf", "New Form"));

    // when
    findElementBy(By.id("stepdown_1")).click();
    findElementBy(By.id("printstepdown_1")).click();

    // then
    assertRowEquals(findElements(By.cssSelector(stepsSel)),
            Arrays.asList("Form Name", "New Formsamplewf", "New Form"));
    assertRowEquals(findElements(By.cssSelector(printstepsSel)),
            Arrays.asList("Form Name", "New Formsamplewf", "New Form"));
}

From source file:com.formkiq.web.WorkflowEditorControllerIntegrationTest.java

License:Apache License

/**
 * testAddWorkflow19()./* www  . ja  v  a  2  s  .c  o  m*/
 * change section name.
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow19() throws Exception {
    // given
    // when - add step
    clickAddNewWorkflow();
    addBlankForm();
    menuDragAndDrop("menu-textbox");

    findElementBy(By.className("button-section-edit")).click();

    getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("fieldeditorform")));

    findElementBy(By.name("title")).sendKeys("samplesection");
    //findElementBy(By.className("form-modal-update-button")).click();
    click(By.name("_eventId_next"));

    // then
    getWait().until(ExpectedConditions.invisibilityOfElementLocated(By.id("fieldeditorform")));

    assertEquals("samplesection", findElementBy(By.className("button-section-edit")).getText().trim());

    // when
    findElementBy(By.className("button-section-edit")).click();

    // then
    getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("fieldeditorform")));
    assertEquals("samplesection", findElementBy(By.name("title")).getAttribute("value"));
}

From source file:com.formkiq.web.WorkflowEditorControllerIntegrationTest.java

License:Apache License

/**
 * testAddWorkflow20().//from  w  w w.  j  a v  a2 s. c o  m
 * set source form
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow20() throws Exception {
    // given
    FormJSONFieldType typeSelect = FormJSONFieldType.TEXTBOX;
    ImmutableMap<String, String> values0 = ImmutableMap.of("20", "Sample Label123", "40",
            "Immediate[immediate]", "25", "Currency");

    // when - add step
    clickAddNewWorkflow();

    addBlankForm();
    findElementBy(By.id("tab_s1e2")).click();

    getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("fieldeditorform")));

    findElementBy(getBy("input", "data-fieldid", "20")).sendKeys("samplewf");
    //findElementBy(By.className("form-modal-update-button")).click();
    click(By.name("_eventId_next"));

    // then
    getWait().until(ExpectedConditions.invisibilityOfElementLocated(By.id("fieldeditorform")));

    assertTrue(findElementBy(By.id("tab_s1e2")).getText().endsWith("New Formsamplewf"));

    // when - add field to first form
    menuDragAndDrop("menu-textbox");
    editField("1", values0);

    // given
    ImmutableMap<String, String> values1 = ImmutableMap.of("20", "Sample Label", "40", "Immediate[immediate]",
            "25", "Currency", "81", "New Formsamplewf", "82", "Sample Label123");

    addBlankForm();
    menuDragAndDrop("menu-textbox");
    editField("1", values1);

    // then
    checkEditField("1", typeSelect, values1);
}

From source file:com.formkiq.web.WorkflowEditorControllerIntegrationTest.java

License:Apache License

/**
 * testAddWorkflow23()./*from   w w w  . j  av a  2s  .  co m*/
 * add formula and then edit.
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow23() throws Exception {
    // given
    int step = 2;
    ImmutableMap<String, String> values0 = ImmutableMap.of("20", "Sample Label123", "40",
            "Immediate[immediate]", "25", "Currency", "61", "samp");

    // when - add step
    clickAddNewWorkflow();
    addNewStep(step++, "samplewf");

    menuDragAndDrop("menu-textbox");
    editField("1", values0);

    // given
    ImmutableMap<String, String> values1 = ImmutableMap.of("20", "Sample Label", "61", "tvariable", "83",
            "New Formsamplewf", "84", "samp", "85", "");

    // when
    addNewStep(step++, "test");

    menuDragAndDrop("menu-formula");
    editField("1", values1);

    // then
    clickEditFieldButton("1");

    getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("fieldeditorform")));

    String actual = findElementBy(By.name("78")).getAttribute("value");
    assertEquals("'New Formsamplewf'!samp", actual);
}

From source file:com.formkiq.web.WorkflowEditorControllerIntegrationTest.java

License:Apache License

/**
 * testAddWorkflow26()./*from w  w w  .  j a v  a2  s  .c  o m*/
 * edit Workflow Output
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow26() throws Exception {
    // given
    byte[] pdf = Resources.getResourceAsBytes("/sample-form1.pdf");

    // when - add step
    clickAddNewWorkflow();
    findElementBy(By.id("button_add_step")).click();

    JavascriptExecutor executor = (JavascriptExecutor) getDriver();
    executor.executeScript("var myZone, blob, base64Image;\n" + "base64Image = '" + Strings.encode(pdf) + "'\n"
            + "myZone = Dropzone.forElement(document.body);\n"
            + "function base64toBlob(r,e,n){e=e||\"\",n=n||512;for"
            + "(var t=atob(r),a=[],o=0;o<t.length;o+=n){for" + "(var l=t.slice(o,o+n),h=new Array(l.length),"
            + "b=0;b<l.length;b++)h[b]=l.charCodeAt(b);" + "var v=new Uint8Array(h);a.push(v)}"
            + "var c=new Blob(a,{type:e});return c}" + "blob = base64toBlob(base64Image, 'application/pdf');"
            + "blob.name = 'sample.pdf';\n" + "myZone.addFile(blob);");

    // then
    waitUntilPageSourceText("PDF Form Example");

    // when
    findElementBy(By.id("tab_s1e1")).click();
    findElementBy(By.id("output_0")).click();

    // then
    assertTrue(getPageSource().contains("PDF Form Example"));

    // given
    final int index = 5;

    // when
    new Select(findElementBy(By.name("field_1"))).selectByIndex(index);
    findElementBy(By.id("button_save")).click();

    // then
    assertEquals("FormKiQ Server - Dashboard", getTitle());

    // given
    String ttoken = login();
    UserDTO user = getUserDTO(ttoken, null);
    String folder = user.getFolders().get(0).getUUID().toString();

    // when
    FolderFormsListDTO dto = getFolderFileList(ttoken, folder, null);

    // then
    assertFalse(dto.getForms().isEmpty());

    // given
    FormDTO fdto = Collections.max(dto.getForms(), Comparator.comparing(s -> s.getInserteddate()));

    String uuid = fdto.getUUID();

    // when
    byte[] data = getFolderFile(ttoken, folder, uuid, MediaType.valueOf(ACCEPT_HEADER_V1 + "+zip"), false)
            .getBody();
    ArchiveDTO archive = this.archiveService.extractJSONFromZipFile(data);

    // then
    WorkflowOutputPdfForm o = (WorkflowOutputPdfForm) archive.getWorkflow().getOutputs().get(0);
    List<WorkflowOutputFormField> pfields = o.getFields();
    String formname = "PDF Form Example[" + archive.getForms().values().iterator().next().getUUID() + "]";

    int i = 0;
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Given Name:[1]", "Given Name Text Box");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Address 2:[5]", "Family Name Text Box");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Address 1:[3]", "Address 1 Text Box");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "House nr:[4]", "House nr Text Box");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Address 2:[5]", "Address 2 Text Box");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Postcode:[6]", "Postcode Text Box");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "City:[7]", "City Text Box");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Country:[8]", "Country Combo Box");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Gender:[9]", "Gender List Box");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Height (cm):[10]", "Height Formatted Field");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Driving License:[11]",
            "Driving License Check Box");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Deutsch[12]", "Language 1 Check Box");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "English[13]", "Language 2 Check Box");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Franais[14]", "Language 3 Check Box");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Esperanto[15]", "Language 4 Check Box");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Latin[16]", "Language 5 Check Box");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Favourite colour:[17]",
            "Favourite Colour List Box");
}

From source file:com.formkiq.web.WorkflowEditorControllerIntegrationTest.java

License:Apache License

/**
 * testAddWorkflow27()./*from   w w  w . j ava2  s  . c  o m*/
 * edit DOCX Workflow Output
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow27() throws Exception {
    // given
    String docname = "sample1.docx";
    byte[] dat = Resources.getResourceAsBytes("/" + docname);

    // when - add step
    clickAddNewWorkflow();
    findElementBy(By.id("button_add_step")).click();

    JavascriptExecutor executor = (JavascriptExecutor) getDriver();
    executor.executeScript("var myZone, blob, base64Image;\n" + "base64Image = '" + Strings.encode(dat) + "'\n"
            + "myZone = Dropzone.forElement(document.body);\n"
            + "function base64toBlob(r,e,n){e=e||\"\",n=n||512;for"
            + "(var t=atob(r),a=[],o=0;o<t.length;o+=n){for" + "(var l=t.slice(o,o+n),h=new Array(l.length),"
            + "b=0;b<l.length;b++)h[b]=l.charCodeAt(b);" + "var v=new Uint8Array(h);a.push(v)}"
            + "var c=new Blob(a,{type:e});return c}" + "blob = base64toBlob(base64Image, 'application/pdf');"
            + "blob.name = '" + docname + "';" + "myZone.addFile(blob);");

    // then
    assertEquals("sample1", findElementBy(By.id("tab_s1e2")).getText().trim());

    // when
    findElementBy(By.id("tab_s1e1")).click();
    findElementBy(By.id("output_0")).click();

    // then
    assertTrue(getPageSource().contains("sample"));
    WebElement select = findElementBy(By.name("outputDocumentType"));
    assertEquals("DOCX,PDF", select.getText().trim().replaceAll("[\\s]+", ","));
    assertEquals("DOCX", new Select(select).getFirstSelectedOption().getText());

    // given
    final int index = 5;

    // when
    new Select(select).selectByValue("PDF");
    new Select(findElementBy(By.name("field_1"))).selectByIndex(index);
    findElementBy(By.id("button_save")).click();

    // then
    assertEquals("FormKiQ Server - Dashboard", getTitle());

    // given
    String ttoken = login();
    UserDTO user = getUserDTO(ttoken, null);
    String folder = user.getFolders().get(0).getUUID().toString();

    // when
    FolderFormsListDTO dto = getFolderFileList(ttoken, folder, null);

    // then
    assertFalse(dto.getForms().isEmpty());

    // given
    FormDTO fdto = Collections.max(dto.getForms(), Comparator.comparing(s -> s.getInserteddate()));

    String uuid = fdto.getUUID();

    // when
    byte[] data = getFolderFile(ttoken, folder, uuid, MediaType.valueOf(ACCEPT_HEADER_V1 + "+zip"), false)
            .getBody();
    ArchiveDTO archive = this.archiveService.extractJSONFromZipFile(data);

    // then
    WorkflowOutputDocx o = (WorkflowOutputDocx) archive.getWorkflow().getOutputs().get(0);
    List<WorkflowOutputFormField> pfields = o.getFields();
    String formname = "sample1[" + archive.getForms().values().iterator().next().getUUID() + "]";

    int i = 0;
    assertWorkflowOutputFormField(pfields.get(i++), formname, "DAY[1]", "DAY");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Trade Name[5]", "Month");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Year[3]", "Year");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "LegalName[4]", "LegalName");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Trade Name[5]", "Trade Name");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "ADDRESS[6]", "ADDRESS");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "SUITE[7]", "SUITE");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "CITY[8]", "CITY");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "PROVINCE[9]", "PROVINCE");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "POSTALCODE[10]", "POSTALCODE");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "FAX NUMBER[11]", "FAX NUMBER");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "CONTACT NAME[12]", "CONTACT NAME");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "CONTACT TITLE[13]", "CONTACT TITLE");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "EMAIL[14]", "EMAIL");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Lease Date[15]", "Lease Date");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Driver's License[16]", "Driver's License");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Passport[17]", "Passport");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Checkbox[18]", "Checkbox");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "SIG[19]", "SIG");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "PRINT NAME[20]", "PRINT NAME");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "TITLE[21]", "TITLE");
}

From source file:com.fpt.datht.iap.AutoIAP.java

public static void autoCheck() {

    for (int c = 1; c < count; c++) {

        driver.get(slots[c]);//  w  w w. ja v a2 s.  co m
        try {
            new WebDriverWait(driver, 5)
                    .until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//input[@type='submit']")));

        } catch (TimeoutException ex) {
            driver.get(slots[c].replaceAll("add.php", "edit.php"));

        }
        new WebDriverWait(driver, 10)
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//input[@type='submit']")));
        for (Student st : students) {

            List<WebElement> els = driver.findElements(By.name(st.name));
            els.stream().filter((e) -> (e.getAttribute("value").equals("1"))).forEach((e) -> {
                e.click();
            });
        }
        el = driver.findElement(By.xpath(".//input[@type='submit']"));
        el.click();
        try {
            new WebDriverWait(driver, 3).until(
                    ExpectedConditions.invisibilityOfElementLocated(By.xpath(".//input[@type='submit']")));
        } catch (TimeoutException ex) {
            break;

        }

    }

}

From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.utils.SeleniumUtils.java

License:Apache License

/***
 * Gets an element by name or id/*from  w ww . j  a  v a2  s.  c om*/
 * 
 * @param driver
 * @param nameOrID
 * @return
 */
public static WebElement getByNameOrID(WebDriver driver, String nameOrID) {
    WebElement element = null;
    // try getting the element by name
    try {
        element = driver.findElement(By.name(nameOrID));
    } catch (Exception ex) {

    }
    if (null == element) {
        try {
            element = driver.findElement(By.id(nameOrID));
        } catch (Exception ex) {

        }
    }
    return element;
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlFileInput2Test.java

License:Apache License

/**
 * @throws Exception if an error occurs/*from   w w w. ja  va  2s.  co m*/
 */
@Test
@Alerts(DEFAULT = { "CONTENT_TYPE:application/octet-stream", "charset" }, IE = { "CONTENT_TYPE:text/plain",
        "charset" })
@NotYetImplemented(IE)
public void contentType() throws Exception {
    final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
    servlets.put("/upload1", Upload1Servlet.class);
    servlets.put("/upload2", ContentTypeUpload2Servlet.class);
    startWebServer("./", new String[0], servlets);

    final WebDriver driver = getWebDriver();
    driver.get("http://localhost:" + PORT + "/upload1");
    String path = getClass().getClassLoader().getResource("realm.properties").toExternalForm();
    if (driver instanceof InternetExplorerDriver || driver instanceof ChromeDriver) {
        path = path.substring(path.indexOf('/') + 1).replace('/', '\\');
    }
    driver.findElement(By.name("myInput")).sendKeys(path);
    driver.findElement(By.id("mySubmit")).click();

    final String pageSource = driver.getPageSource();
    assertTrue(pageSource, pageSource.contains(getExpectedAlerts()[0]));
    assertFalse(pageSource, pageSource.contains(getExpectedAlerts()[1]));
}