Example usage for org.openqa.selenium WebElement getAttribute

List of usage examples for org.openqa.selenium WebElement getAttribute

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement getAttribute.

Prototype

String getAttribute(String name);

Source Link

Document

Get the value of the given attribute of the element.

Usage

From source file:com.example.selenium.find.elements.FindElementsTest.java

@Test
public void findByLinkTest() {

    try {//  w  w w.j  a  va 2s.  c o  m
        WebElement element = selenium.findElement(By.linkText("Login"));
        System.out.println("Element Attrbutes =" + element.getAttribute("href"));
        Assert.assertNotNull(element);
    } catch (NoSuchElementException ex) {
        Logger.getLogger(FindElementsTest.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.example.selenium.find.elements.FindElementXPath.java

@Test
public void findByOperatorAnd() {
    WebElement element = driver.findElement(By.xpath("//input[@type='text' and @placeholder='Username']"));
    System.out.println("Element Value =" + element.getAttribute("placeholder"));
}

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

License:Apache License

/**
 * Find Match Option./*w ww  .jav a 2  s. c  om*/
 * @param select {@link Select}
 * @param value {@link String}
 * @return int
 */
public int findMatchOption(final Select select, final String value) {

    int i = -1;
    for (WebElement e : select.getOptions()) {
        i++;
        String v = extractLabelAndValue(e.getAttribute("value")).getRight();
        if (v.equals(value)) {
            break;
        }
    }

    return i;
}

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

License:Apache License

/**
 * Click Submit Button by name./*from w  w  w  .  j  a  v  a2 s  . c o  m*/
 * @param name {@link String}
 * @param text {@link String}
 * @param timeout long
 */
private void submitByName(final String name, final String text, final long timeout) {

    List<WebElement> elements = getSubmitButtons();
    for (WebElement element : elements) {
        if (name.equals(element.getAttribute("name"))) {
            assertEquals(text, element.getText());
            element.click();
            break;
        }
    }
}

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

License:Apache License

/**
 * testWorkflow01()./*  www. j a va  2 s.  c o  m*/
 * get workflow as ADMIN
 * @throws Exception Exception
 */
@Test
public void testCreateWorkflow01() throws Exception {
    // given
    final long sleep = 250L;
    FormJSON form = TestDataBuilder.createStoreReceipt();
    Workflow workflow = TestDataBuilder.createWorkflow(form);

    String token = login();
    String folder = createFolder(token, getDefaultEmail());

    addFileToFolder(token, folder, workflow, form);

    // when
    login(getDefaultEmail());
    getDriver().navigate().to(getDefaultHostAndPort() + "/user/dashboard");
    waitForJSandJQueryToLoad();

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

    findElementBy(By.className("add_0")).click();

    // then (verify on correct page)
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e1", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - Store Receipt", getTitle());

    // when (enter data)
    WebElement element = findElementBy(By.name("1"));
    element.sendKeys("10");

    element = findElementBy(By.name("1"));
    assertEquals("10", element.getAttribute("value"));

    JavascriptExecutor jsExecutor = (JavascriptExecutor) getDriver();
    jsExecutor.executeScript("calculate();", element);

    Thread.sleep(sleep);

    getDriver().navigate().refresh();

    // then (verify data calculations)
    element = findElementBy(By.name("2"));
    assertEquals("$0.70", element.getAttribute("value"));

    element = findElementBy(By.name("3"));
    assertEquals("$7.99", element.getAttribute("value"));

    element = findElementBy(By.name("4"));
    assertEquals("$18.69", element.getAttribute("value"));

    List<WebElement> elements = getSubmitButtons();
    assertEquals(1, elements.size());

    // when (submit)
    submitByName("_eventId_next", "Next");

    // then verify complete
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e2", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - Sample WF Complete", getTitle());

    assertTrue(getDriver().getPageSource().contains("end-of-document"));

    String pageSource = getDriver().getPageSource();
    assertTrue(pageSource.contains("The workflow has been saved."));

    FolderFormsListDTO formlist = getFolderFileList(token, folder, workflow.getUUID());

    assertEquals(1, formlist.getForms().size());
    FormDTO fdto = formlist.getForms().get(0);
    assertNotEquals(workflow.getUUID(), fdto.getUUID());

    byte[] data = getFolderFile(token, folder, fdto.getUUID(), MediaType.valueOf(ACCEPT_HEADER_V1 + "+zip"),
            false).getBody();
    ArchiveDTO archive = this.archiveService.extractJSONFromZipFile(data);
    workflow = archive.getWorkflow();

    assertNotNull(workflow);
    assertEquals(1, archive.getForms().size());
    form = archive.getForms().values().iterator().next();

    assertTrue(workflow.getSteps().contains(form.getUUID()));
    assertEquals(workflow.getParentUUID(), form.getParentUUID());

    int i = 1;
    assertEquals("$10.00", findField(form, i++).get().getValue());
    assertEquals("$0.70", findField(form, i++).get().getValue());
    assertEquals("$7.99", findField(form, i++).get().getValue());
    assertEquals("$18.69", findField(form, i++).get().getValue());
}

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

License:Apache License

/**
 * Add Field to Form.//from   ww w .j  a  va  2  s  .  c om
 * @param type {@link FormJSONFieldType}
 */
private void addField(final FormJSONFieldType type) {
    WebElement el = findElementBy(By.className("form-section"));
    JavascriptExecutor executor = (JavascriptExecutor) getDriver();
    executor.executeScript("postJSON('/api/flow?execution=' + getExecution() + " + "'&_eventId_fieldadd="
            + el.getAttribute("data-uuid") + ",1&type=" + type + "', null);");
    getDriver().navigate().refresh();
}

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

License:Apache License

/**
 * Move Field.//from  w  w  w. ja  v  a  2s .  c  o  m
 * @param start {@link String}
 * @param end {@link String}
 */
private void moveField(final String start, final String end) {
    WebElement el = findElementBy(By.className("form-section"));
    JavascriptExecutor executor = (JavascriptExecutor) getDriver();
    executor.executeScript("postJSON('/api/flow?execution=' + getExecution() + " + "'&_eventId_fieldmove="
            + el.getAttribute("data-uuid") + "," + start + el.getAttribute("data-uuid") + "," + end
            + "', null);");
    getDriver().navigate().refresh();
}

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

License:Apache License

/**
 * testAddWorkflow07()./*  w ww.ja va2  s  . com*/
 * add Password and then edit..
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow07() throws Exception {
    // given
    FormJSONFieldType typeSelect = FormJSONFieldType.PASSWORD;
    ImmutableMap<String, String> values = ImmutableMap.of("20", "new field", "40", "Immediate[immediate]");

    // when - add step
    clickAddNewWorkflow();
    addBlankForm();

    menuDragAndDrop("menu-password");

    // then
    WebElement element = findElementBy("input", "data-fieldid", "1");
    assertTrue(element.isDisplayed());
    assertEquals("password", element.getAttribute("type"));

    checkEditField("1", typeSelect, values);
}

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

License:Apache License

/**
 * testAddWorkflow10().//from w w  w. j  ava  2 s  . c o m
 * add Signature Initials and then edit..
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow10() throws Exception {
    // given
    FormJSONFieldType typeSelect = FormJSONFieldType.SIGNATURE_INITIALS;
    ImmutableMap<String, String> values = ImmutableMap.of("20", "new field", "40", "Immediate[immediate]");

    // when - add step
    clickAddNewWorkflow();
    addBlankForm();

    menuDragAndDrop("menu-initials");

    // then
    WebElement element = findElementBy("input", "data-fieldid", "1");
    assertTrue(element.isDisplayed());
    assertEquals("XX", element.getAttribute("placeholder"));

    checkEditField("1", typeSelect, values);
}

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

License:Apache License

/**
 * testAddWorkflow14().// w  w w. j  a v a  2  s.  co m
 * add textbox and then edit with custom formatter..
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow14() throws Exception {
    // given
    FormJSONFieldType typeSelect = FormJSONFieldType.TEXTBOX;
    Map<String, String> values = new LinkedHashMap<>();
    values.put("20", "Sample Label");
    values.put("40", "Immediate[immediate]");
    values.put("44", "Numbers[DecimalPad]");
    values.put("25", "Custom");
    values.put("61", "tvariable");
    values.put("24", "(ddd)");

    // when - add step
    clickAddNewWorkflow();
    addBlankForm();

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

    // then
    WebElement element = findElementBy("input", "data-fieldid", "1");
    assertTrue(element.isDisplayed());

    element.sendKeys("a456");
    assertEquals("(456)", element.getAttribute("value"));

    checkEditField("1", typeSelect, values);
}