Example usage for org.openqa.selenium WebElement clear

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

Introduction

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

Prototype

void clear();

Source Link

Document

If this element is a form entry element, this will reset its value.

Usage

From source file:org.auraframework.integration.test.components.ui.inputDate.InputDateWithLabelUITest.java

License:Apache License

private String pageUpDownHelper(int iterCondition, String keyString) {
    // Making sure the textBox is empty so we always start at the same date
    WebElement element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    element.clear();
    element.sendKeys(TEST_DATE_TO_USE);//from   www.ja  v  a2s . c o m

    openDatePicker();

    String classOfActiveElem = "" + getAuraUITestingUtil().getEval(CLASSNAME);
    element = findDomElement(By.cssSelector("td[class*='" + classOfActiveElem + "']"));

    element = loopThroughKeys(element, keyString, iterCondition, ARIA_SELECTED_SEL, "Shift+Page Up/Down");

    // Selecting the date that we are on to get the value and compare it to what it should be
    element.sendKeys(Keys.SPACE);

    // Setting the input box in focus to get its value
    element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));

    // Checking if the values are equal
    return element.getAttribute("value");
}

From source file:org.auraframework.integration.test.components.ui.inputDate.InputDateWithLabelUITest.java

License:Apache License

private String homeEndButtonHelper(String initDate, Keys buttonToPress) {
    // Getting the input box, making sure it is clear, and sending in the the starting date
    WebElement element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    element.clear();
    element.sendKeys(initDate);/*from w  w  w.  ja  v  a 2 s  .c o  m*/

    // Opening the calendar icon to grab the date we are looking for
    openDatePicker();

    // Grabbing the correct focus cell date
    By selectedDate = By.cssSelector(SELECTED_DATE);
    element = findDomElement(selectedDate);

    // Pressing the home or End button and grabbing the associated date
    element.sendKeys(buttonToPress);

    // Clicking on that element to compare it to the date we should receive
    element = (WebElement) getAuraUITestingUtil().getEval(ACTIVE_ELEMENT);
    element.sendKeys(Keys.ENTER);

    // Repointing to the InputTextBox
    element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));

    // Making sure they are equal
    return element.getAttribute("value");
}

From source file:org.auraframework.integration.test.components.ui.inputSmartNumber.InputNumberUITest.java

License:Apache License

@Test
public void testInputNumber() throws Exception {
    open(LOCALIZATION_TEST_URL);/* w  w w .  j  ava2 s  . c om*/

    WebElement input = findDomElement(By.cssSelector(".input"));
    WebElement submit = findDomElement(By.cssSelector(".uiButton"));

    // integer
    input.clear();
    input.sendKeys("987654321");
    submit.click();
    getAuraUITestingUtil().waitForElementText(OUTPUT_LOCATOR, "987654321", true);

    // negative integer
    input.clear();
    input.sendKeys("-123");
    submit.click();
    getAuraUITestingUtil().waitForElementText(OUTPUT_LOCATOR, "-123", true);
}

From source file:org.auraframework.integration.test.components.ui.inputSmartNumber.InputNumberUITest.java

License:Apache License

@Test
public void testLocalizedInputNumber() throws Exception {
    open(LOCALIZATION_TEST_URL);/* w  w w .ja v a2s. c  o  m*/

    WebElement input = findDomElement(By.cssSelector(".input"));
    WebElement submit = findDomElement(By.cssSelector(".uiButton"));

    // integer
    input.clear();
    input.sendKeys("123456789");
    submit.click();
    getAuraUITestingUtil().waitForElementText(OUTPUT_LOCATOR, "123456789", true);

    // decimal
    input.clear();
    input.sendKeys("123456.789");
    submit.click();
    getAuraUITestingUtil().waitForElementText(OUTPUT_LOCATOR, "123456.789", true);

    // negative integer
    input.clear();
    input.sendKeys("-123456");
    submit.click();
    getAuraUITestingUtil().waitForElementText(OUTPUT_LOCATOR, "-123456", true);

    // negative decimal
    input.clear();
    input.sendKeys("-123.456");
    submit.click();
    getAuraUITestingUtil().waitForElementText(OUTPUT_LOCATOR, "-123.456", true);
}

From source file:org.auraframework.integration.test.components.ui.inputText.InputTextUITest.java

License:Apache License

/**
 * Test Case for W-1689213//from w ww.  java  2  s .c  o m
 */
@Test
public void testInputTextWithLabel() throws Exception {
    open(TEST_CMP);
    WebElement div = findDomElement(By.id("inputwithLabel"));
    WebElement input = div.findElement(By.tagName("input"));
    WebElement outputDiv = findDomElement(By.id("output"));

    String inputAuraId = "inputwithLabel";
    String valueExpression = getAuraUITestingUtil().getValueFromCmpRootExpression(inputAuraId, "v.value");
    String defExpectedValue = (String) getAuraUITestingUtil().getEval(valueExpression);
    assertEquals("Default value should be the same", inputAuraId, defExpectedValue);

    // AndroidDriver likes to type things in all caps so modify input to accommodate.
    String inputText = "UPDATEDTEXT";
    input.clear();
    input.click();
    input.sendKeys(inputText);
    outputDiv.click(); // to simulate tab behavior for touch browsers
    String actualText = (String) getAuraUITestingUtil().getEval(valueExpression);
    assertEquals("Value of Input text shoud be updated", inputText, actualText);
}

From source file:org.auraframework.integration.test.components.ui.inputTextArea.InputTextAreaUITest.java

License:Apache License

/**
 * Test Case for W-1731003 ui:inputTextArea throws error when value is changed
 *//*from   www  . j  a  va  2  s.  co  m*/
@Test
public void testInputTextAreaWithLabel() throws Exception {
    open(TEST_CMP);
    WebElement div = findDomElement(By.id("textAreaWithLabel"));
    WebElement input = div.findElement(By.tagName("textarea"));
    WebElement outputDiv = findDomElement(By.id("output"));

    String inputAuraId = "textAreaWithLabel";
    String valueExpression = getAuraUITestingUtil().getValueFromCmpRootExpression(inputAuraId, "v.value");
    String defExpectedValue = (String) getAuraUITestingUtil().getEval(valueExpression);
    assertEquals("Default value for inputTextArea should be the same", inputAuraId, defExpectedValue);

    // AndroidDriver likes to type things in all caps so modify input to accommodate.

    String inputText = "UPDATEDTEXT";
    input.clear();
    input.click();
    input.sendKeys(inputText);
    outputDiv.click(); // to simulate tab behavior for touch browsers
    String actualText = (String) getAuraUITestingUtil().getEval(valueExpression);
    assertEquals("Value of Input text Area shoud be updated", inputText, actualText);
}

From source file:org.auraframework.integration.test.components.ui.inputTextArea.InputTextAreaUITest.java

License:Apache License

@Test
public void testEncodedTextAreaBehavior() throws Exception {
    open(TEST_CMP);/*from   ww w. ja v a 2s  . co m*/
    WebElement div = findDomElement(By.id("textAreaWithLabel"));
    WebElement input = div.findElement(By.tagName("textarea"));
    WebElement outputDiv = findDomElement(By.id("output"));

    String inputAuraId = "textAreaWithLabel";
    String valueExpression = getAuraUITestingUtil().getValueFromCmpRootExpression(inputAuraId, "v.value");

    String inputText = String.format("%s%n%s%n%s%n%s", "LINE1", "LINE2", "LINE3", "LINE4");
    input.clear();
    input.click();
    input.sendKeys(inputText);
    outputDiv.click(); // to simulate tab behavior for touch browsers
    String actualText = (String) getAuraUITestingUtil().getEval(valueExpression);
    assertEquals("Total number of bytes with \r\n does not match", inputText.getBytes().length + 3,
            actualText.getBytes().length);
    assertEquals("Value of Input text Area shoud be updated after removing carriage return", inputText,
            actualText.replaceAll("(\\r)", ""));
}

From source file:org.auraframework.integration.test.components.ui.inputTextArea.InputTextAreaUITest.java

License:Apache License

@Test
public void testTextAreaWithMultipleLinesOfText() throws Exception {
    open(TEST_CMP2);/*from   w  w w. jav a2 s  .  co  m*/
    WebElement div = findDomElement(By.id("textAreaWithLabel"));
    WebElement input = div.findElement(By.tagName("textarea"));
    WebElement outputDiv = findDomElement(By.id("output"));

    String inputAuraId = "textAreaWithLabel";
    String valueExpression = getAuraUITestingUtil().getValueFromCmpRootExpression(inputAuraId, "v.value");

    String inputText = String.format("%s%n%s%n%s%n%s", "LINE1", "LINE2", "LINE3", "L4");
    input.clear();
    input.click();
    input.sendKeys(inputText);
    input.sendKeys(Keys.ARROW_LEFT, Keys.ARROW_LEFT);
    String inputNewString = "L5";
    input.sendKeys(inputNewString);
    inputText = String.format("%s%n%s%n%s%n%s", "LINE1", "LINE2", "LINE3", "L5L4");
    outputDiv.click(); // to simulate tab behavior for touch browsers
    String actualText = (String) getAuraUITestingUtil().getEval(valueExpression);
    assertEquals("Total number of bytes with \r\n does not match", inputText.getBytes().length + 3,
            actualText.getBytes().length);
    assertEquals("Value of Input text Area shoud be updated after removing carriage return", inputText,
            actualText.replaceAll("(\\r)", ""));
}

From source file:org.auraframework.integration.test.components.ui.modalOverlay.Panel2ModalOverlayUITest.java

License:Apache License

private void verifyPressingEscOnMultipleModalDestorysModal(String locator, boolean autoFocus)
        throws MalformedURLException, URISyntaxException, InterruptedException {
    String url = APP;//from   w  w  w .j a v a  2  s.c  o  m
    boolean isPanel = locator.contains(PANEL_DIALOG);
    String errorMessage = "modal";
    if (isPanel) {
        url += "?" + PARAM_PANEL_TYPE + "panel";
        errorMessage = "panel";
    }

    open(url);

    // disable autoFocus for modal 1
    if (!autoFocus) {
        WebElement autoFocusElement = findDomElement(By.cssSelector(INPUT_AUTOFOCUS));
        autoFocusElement.click();
    }

    openPanel();
    if (locator.contains(PANEL_MODAL)) {
        waitForModalOpen();
    } else {
        waitForPanelDialogOpen();
        WebElement fistInputElement = findDomElements(By.cssSelector(INPUT_PANELTYPE)).get(1);
        fistInputElement.clear();
        fistInputElement.click();
        fistInputElement.sendKeys("panel");
    }

    verifyModalPanelIsActive(String.format("First %s should have class active", errorMessage), locator, true,
            0);
    openPanel(2);
    waitForNumberOfPanels(locator, 2);

    verifyModalPanelIsActive(
            String.format("First %s should not have class active after opening second modal", errorMessage),
            locator, false, 0);
    verifyModalPanelIsActive(String.format("Second %s should have class active", errorMessage), locator, true,
            1);

    waitTillFocusOnTopElement();

    WebElement activeElement = (WebElement) getAuraUITestingUtil().getEval(ACTIVE_ELEMENT);
    activeElement.sendKeys(Keys.ESCAPE);
    waitForNumberOfPanels(locator, 1);

    verifyModalPanelIsActive(String.format("First %s should have class active after press ESC on 2nd %s",
            errorMessage, errorMessage), locator, true, 0);

    activeElement = (WebElement) getAuraUITestingUtil().getEval(ACTIVE_ELEMENT);
    activeElement.sendKeys(Keys.ESCAPE);
    waitForNumberOfPanels(locator, 0);
}

From source file:org.auraframework.integration.test.localization.LocalizationAppUITest.java

License:Apache License

@ExcludeBrowsers({ BrowserType.IE9, BrowserType.IE10, BrowserType.SAFARI, BrowserType.ANDROID_PHONE,
        BrowserType.ANDROID_TABLET, BrowserType.IPAD, BrowserType.IPHONE })
// Checking functionality of the inputDate/outputDate components
@Test/*from  w w  w .  jav  a2s  .  c o m*/
public void testDateComponents() throws Exception {
    open(URL);

    // initial load
    WebElement elementInput = findDomElement(By.cssSelector(".uiInputDate .input"));
    WebElement elementoutput = findDomElement(By.cssSelector(".uiOutputDate"));
    assertEquals("InputDate component rendered with wrong value", "Sep 23, 2004",
            elementInput.getAttribute("value"));
    assertEquals("outputDate component rendered with wrong value", "Sep 23, 2004", elementoutput.getText());

    // Tab out
    elementInput.click();
    elementInput.clear();
    elementInput.sendKeys("Sep 23, 2005");
    getAuraUITestingUtil().pressTab(elementInput);

    assertEquals("InputDate component rendered with wrong value", "Sep 23, 2005",
            elementInput.getAttribute("value"));
    assertEquals("outputDate component rendered with wrong value", "Sep 23, 2005", elementoutput.getText());

    // Submit click
    elementInput.click();
    elementInput.clear();
    elementInput.sendKeys("Sep 23, 2006");
    // Hide the datepicker
    WebElement yearSelector = findDomElement(By.cssSelector(".visible select"));
    yearSelector.sendKeys(Keys.ESCAPE);

    WebElement elementButton = findDomElement(By.cssSelector("button[title~='Date']"));
    elementButton.click();

    assertEquals("InputDate component rendered with wrong value", "Sep 23, 2006",
            elementInput.getAttribute("value"));
    assertEquals("outputDate component rendered with wrong value", "Sep 23, 2006", elementoutput.getText());
}