Example usage for org.openqa.selenium WebElement sendKeys

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

Introduction

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

Prototype

void sendKeys(CharSequence... keysToSend);

Source Link

Document

Use this method to simulate typing into an element, which may set its value.

Usage

From source file:com.liferay.cucumber.selenium.BaseWebDriverImpl.java

License:Open Source License

@Override
public void uploadFile(String location, String value) {
    makeVisible(location);/*from www  . j av  a 2 s .com*/

    WebElement webElement = getWebElement(location);

    webElement.sendKeys(value);
}

From source file:com.liferay.cucumber.selenium.WebDriverHelper.java

License:Open Source License

public static void type(WebDriver webDriver, String locator, String value) {
    WebElement webElement = getWebElement(webDriver, locator);

    if (!webElement.isEnabled()) {
        return;//www  .ja  v a 2s  . c  o m
    }

    webElement.clear();

    webElement.sendKeys(value);
}

From source file:com.liferay.faces.bridge.test.integration.demo.applicant.ApplicantTesterBase.java

License:Open Source License

@Test
public void runApplicantPortletTest_I_FileUpload() throws IOException {

    BrowserDriver browserDriver = getBrowserDriver();
    String fileUploadChooserXpath = getFileUploadChooserXpath();
    WebElement fileUploadChooser = browserDriver.findElementByXpath(fileUploadChooserXpath);

    // Set PrimeFaces p:fileUpload transform style to "none" since it causes the element to not be displayed
    // according to Selenium (although the element is visible to users).
    browserDriver.executeScriptInCurrentWindow("arguments[0].style.transform = 'none';", fileUploadChooser);

    // Workaround https://github.com/ariya/phantomjs/issues/10993 by removing the multiple attribute from <input
    // type="file" />
    if (browserDriver.getBrowserName().equals("phantomjs")) {

        browserDriver.executeScriptInCurrentWindow(
                "var multipleFileUploadElements = document.querySelectorAll('input[type=\"file\"][multiple]');"
                        + "for (var i = 0; i < multipleFileUploadElements.length; i++) {"
                        + "multipleFileUploadElements[i].removeAttribute('multiple'); }");
    }/* w w  w .  ja v  a 2s .  c  o  m*/

    fileUploadChooser.sendKeys(getFileSystemPathForResource(BridgeTestUtil.LIFERAY_JSF_JERSEY_PNG_FILE_NAME));
    submitFile(browserDriver);
    getWaitingAsserter().assertTextPresentInElement("jersey", getUploadedFileXpath());
}

From source file:com.liferay.faces.bridge.test.integration.issue.primefaces.FACES_3250PortletTester.java

License:Open Source License

private void testFACES_3250FileUpload(BrowserDriver browserDriver, WaitingAsserter waitingAsserter, String mode)
        throws IOException {

    WebElement fileUploadChooser = browserDriver
            .findElementByXpath("//input[contains(@id,':" + mode + "FileUpload')]");

    // Set PrimeFaces p:fileUpload transform style to "none" since it causes the element to not be displayed
    // according to Selenium (although the element is visible to users).
    browserDriver.executeScriptInCurrentWindow("arguments[0].style.transform = 'none';", fileUploadChooser);

    // Workaround https://github.com/ariya/phantomjs/issues/10993 by removing the multiple attribute from <input
    // type="file" />
    if (browserDriver.getBrowserName().equals("phantomjs")) {

        browserDriver.executeScriptInCurrentWindow(
                "var multipleFileUploadElements = document.querySelectorAll('input[type=\"file\"][multiple]');"
                        + "for (var i = 0; i < multipleFileUploadElements.length; i++) {"
                        + "multipleFileUploadElements[i].removeAttribute('multiple'); }");
    }//w w w  .j a  va  2s.  c o  m

    fileUploadChooser.sendKeys(getFileSystemPathForResource(BridgeTestUtil.LIFERAY_JSF_JERSEY_PNG_FILE_NAME));

    if (mode.toLowerCase(Locale.ENGLISH).contains("simplemode")) {
        browserDriver.clickElementAndWaitForRerender("//button[contains(@id,':" + mode + "SubmitButton')]");
    }

    waitingAsserter.assertTextPresentInElement("jersey", "//span[contains(@id,':" + mode + "FileName')]");
}

From source file:com.liferay.faces.portal.test.integration.demo.PrimeFacesUsersPortletTester.java

License:Open Source License

@Test
public void runPrimeFacesUsersPortletTest_E_DetailViewFileUpload() {

    BrowserDriver browserDriver = getBrowserDriver();

    // 1. Enter "john.adams" in the Screen Name filter so that *John Adams* appears as the only user in the
    // list./*from   www  .j a v a 2  s  . co m*/
    filterColumnByFullScreenName(browserDriver, "john.adams");

    // 2. Select *John Adams* from the list of users so that the corresponding user's data is displayed in an
    // editable form.
    browserDriver.clickElement(SCREEN_NAME_CELL_XPATH);
    browserDriver.waitForElementDisplayed(FIRST_NAME_FIELD_XPATH);

    // 3. Verify that the file upload chooser is displayed.
    String fileUploadChooserXpath = "//input[@type='file']";
    WebElement fileUploadChooser = browserDriver.findElementByXpath(fileUploadChooserXpath);

    // TECHNICAL NOTE:
    // Set PrimeFaces p:fileUpload transform style to "none" since it causes the element to not be displayed
    // according to Selenium (although the element is visible to users).
    browserDriver.executeScriptInCurrentWindow("arguments[0].style.transform = 'none';", fileUploadChooser);
    browserDriver.waitForElementEnabled(fileUploadChooserXpath + "/..");

    // 4. Prior to uploading an image, note the placeholder portrait that is displayed.
    String portraitXpath = "//div/img[contains(@id,':portrait')]";
    WebElement portraitElement = browserDriver.findElementByXpath(portraitXpath);
    Dimension originalPlaceholderPortraitSize = portraitElement.getSize();

    // 5. Click the *Choose* button and select "liferay-jsf-jersey.png" for upload.
    fileUploadChooser.sendKeys(TestUtil.JAVA_IO_TMPDIR + "liferay-jsf-jersey.png");
    browserDriver.waitFor(ExpectedConditions.stalenessOf(portraitElement));

    WaitingAsserter waitingAsserter = getWaitingAsserter();
    waitingAsserter.assertElementDisplayed(portraitXpath);
    portraitElement = browserDriver.findElementByXpath(portraitXpath);

    // 6. Verify that the displayed portrait is different than the original placeholder portrait, and note the
    // displayed portrait.
    Dimension uploadedPortraitSize = portraitElement.getSize();
    Assert.assertFalse(areImageSizesEqual(originalPlaceholderPortraitSize, uploadedPortraitSize));

    // 7. Click the *Submit* button to submit the portrait update and go back to the list of users.
    browserDriver.clickElement(SUBMIT_BUTTON_XPATH);
    browserDriver.waitForElementDisplayed(SCREEN_NAME_CELL_XPATH);

    // 8. Select *John Adams* from the list of users so that the corresponding user's data is displayed in an
    // editable form.
    browserDriver.clickElement(SCREEN_NAME_CELL_XPATH);
    browserDriver.waitForElementDisplayed(FIRST_NAME_FIELD_XPATH);

    // 9. Verify that the displayed portrait is the same uploaded portrait and different than the original
    // placeholder portrait.
    portraitElement = browserDriver.findElementByXpath(portraitXpath);

    Dimension expectedUploadedPortraitSize = uploadedPortraitSize;
    Dimension actualUploadedPortraitSize = portraitElement.getSize();
    Assert.assertTrue(areImageSizesEqual(expectedUploadedPortraitSize, actualUploadedPortraitSize));
    Assert.assertFalse(areImageSizesEqual(originalPlaceholderPortraitSize, actualUploadedPortraitSize));

    // 10. Click the *Cancel* button to go back to the list of users.
    browserDriver.clickElement(CANCEL_BUTTON_XPATH);
    browserDriver.waitForElementDisplayed(SCREEN_NAME_CELL_XPATH);

    // 11. Clear the filter to see the list of all the users again.
    browserDriver.clearElement(SCREEN_NAME_COLUMN_FILTER_XPATH);
    browserDriver.waitForElementDisplayed(SCREEN_NAME_CELL_2_XPATH);
}

From source file:com.liferay.faces.test.showcase.inputsecret.InputSecretImmediateTester.java

License:Open Source License

@Test
public void runInputSecretImmediateTest() throws Exception {

    Browser browser = Browser.getInstance();
    browser.navigateToURL(inputSecretURL + "/immediate");

    // Wait to begin the test until the submit button is rendered.
    browser.waitForElementVisible(submitButtonXpath);

    // Test that the value submits successfully and the valueChangeListener method is called during the
    // APPLY_REQUEST_VALUES phase.
    WebElement input = browser.getElement(inputXpath);
    String text = "Hello World!";
    input.sendKeys(text);
    browser.performAndWaitForAjaxRerender(browser.createClickAction(submitButtonXpath), modelValueXpath);
    browser.assertElementTextVisible(modelValueXpath, text);
    browser.assertElementVisible(immediateMessage);

    // Test that the value submits successfully and the valueChangeListener method is called during the
    // PROCESS_VALIDATIONS phase.
    input = browser.getElement(inputXpathRight);
    input.sendKeys(text);/* w w w.j  av a2 s.c om*/
    browser.performAndWaitForAjaxRerender(browser.createClickAction(submitButtonXpathRight),
            modelValueXpathRight);
    browser.assertElementTextVisible(modelValueXpathRight, text);
    browser.assertElementVisible(immediateMessageRight);
}

From source file:com.liferay.faces.test.showcase.inputsecret.InputSecretRedisplayTester.java

License:Open Source License

@Test
public void runInputSecretRedisplayTest() throws Exception {

    Browser browser = Browser.getInstance();
    browser.navigateToURL(inputSecretURL + "/redisplay");

    // Wait to begin the test until the submit button is rendered.
    browser.waitForElementVisible(submitButtonXpath);

    // Test that the value submits successfully and the alloy:inputSecret component is intentionally
    // not re-rendered in the DOM.
    WebElement input = browser.getElement(inputSecretXpath);
    String text = "Hello World!";
    input.sendKeys(text);
    browser.performAndWaitForAjaxRerender(browser.createClickAction(submitButtonXpath), modelValueXpath);
    browser.assertElementTextVisible(modelValueXpath, text);

    String redisplayMessage = "//td[contains(text(),'was intentionally not re-rendered')]";
    browser.assertElementVisible(redisplayMessage);

    // Test that the value submits successfully and the entire form (including the alloy:inputSecret component)
    // is re-rendered in the DOM.
    input = browser.getElement(inputSecretXpathRight);
    input.sendKeys(text);/*from   w  w  w.  j  a  va2  s .  co m*/
    browser.clickAndWaitForAjaxRerender(submitButtonXpathRight);
    browser.assertElementTextVisible(modelValueXpathRight, text);

    String redisplayMessageRight = "//td[contains(text(),'entire form')]";
    browser.assertElementVisible(redisplayMessageRight);
}

From source file:com.liferay.faces.test.showcase.inputsecret.InputSecretValidationTester.java

License:Open Source License

@Test
public void runInputSecretValidationTest() throws Exception {

    Browser browser = Browser.getInstance();
    browser.navigateToURL(inputSecretURL + "/validation");

    // Wait to begin the test until the submit button is rendered.
    browser.waitForElementVisible(submitButtonXpath);

    // Test that the web page shows an error message when an invalid value is submitted.
    WebElement input = browser.getElement(inputXpath);
    input.clear();//from ww w.  ja v  a2 s  .  c  o  m

    String invalidText = "HelloWorldcom";
    input.sendKeys(invalidText);
    browser.clickAndWaitForAjaxRerender(submitButtonXpath);
    browser.assertElementVisible(errorXpath);

    // Test that a valid value submits successfully.
    input = browser.getElement(inputXpath);
    input.clear();

    String text = "Hello@World.com";
    input.sendKeys(text);
    browser.clickAndWaitForAjaxRerender(submitButtonXpath);
    browser.assertElementTextVisible(modelValueXpath, text);

    // Test that the web page shows an error message when an invalid value is submitted.
    input = browser.getElement(inputXpathRight);
    input.clear();
    input.sendKeys(invalidText);
    browser.clickAndWaitForAjaxRerender(submitButtonXpathRight);
    browser.assertElementVisible(errorXpath);

    // Test that a valid value submits successfully.
    input = browser.getElement(inputXpathRight);
    input.clear();
    input.sendKeys(text);
    browser.clickAndWaitForAjaxRerender(submitButtonXpathRight);
    browser.assertElementTextVisible(modelValueXpathRight, text);
}

From source file:com.liferay.faces.test.showcase.inputtext.InputTextConversionTester.java

License:Open Source License

@Test
public void runInputTextConversionTest() throws Exception {

    Browser browser = Browser.getInstance();
    browser.navigateToURL(inputTextURL + "/conversion");

    // Wait to begin the test until the submit button is rendered.
    browser.waitForElementVisible(submitButtonXpath);

    // Test that the web page shows an error message when an invalid value is submitted.
    WebElement input = browser.getElement(inputXpath);
    input.clear();//from w  w  w.ja  v  a 2 s.  c o m

    String invalidText = "apr 3 33";
    input.sendKeys(invalidText);
    browser.clickAndWaitForAjaxRerender(submitButtonXpath);
    browser.assertElementVisible(errorXpath);

    // Test that a valid value submits successfully.
    input = browser.getElement(inputXpath);
    input.clear();

    String text = "apr 3, 33";
    input.sendKeys(text);
    browser.clickAndWaitForAjaxRerender(submitButtonXpath);

    String textOutput = "Apr 3, 0033";
    browser.assertElementTextVisible(modelValueXpath, textOutput);

    // Test that the web page shows an error message when an invalid value is submitted.
    input = browser.getElement(inputXpathRight);
    input.clear();
    invalidText = "4/333";
    input.sendKeys(invalidText);
    browser.clickAndWaitForAjaxRerender(submitButtonXpathRight);
    browser.assertElementVisible(errorXpath);

    // Test that a valid value submits successfully.
    input = browser.getElement(inputXpathRight);
    input.clear();
    text = "4/3/33";
    input.sendKeys(text);
    browser.clickAndWaitForAjaxRerender(submitButtonXpathRight);
    textOutput = "04/03/0033";
    browser.assertElementTextVisible(modelValueXpathRight, textOutput);
}

From source file:com.liferay.faces.test.showcase.inputtext.InputTextImmediateTester.java

License:Open Source License

@Test
public void runInputTextImmediateTest() throws Exception {

    Browser browser = Browser.getInstance();
    browser.navigateToURL(inputTextURL + "/immediate");

    // Wait to begin the test until the submit button is rendered.
    browser.waitForElementVisible(submitButtonXpath);

    // Test that the value submits successfully and the valueChangeListener method is called during the
    // APPLY_REQUEST_VALUES phase.
    WebElement input = browser.getElement(inputXpath);
    String text = "Hello World!";
    input.sendKeys(text);
    browser.clickAndWaitForAjaxRerender(submitButtonXpath);
    browser.assertElementTextVisible(modelValueXpath, text);
    browser.assertElementVisible(immediateMessage);

    // Test that the value submits successfully and the valueChangeListener method is called during the
    // PROCESS_VALIDATIONS phase.
    input = browser.getElement(inputXpathRight);
    input.sendKeys(text);//from   w w w.  j  a  v a  2s. c  o  m
    browser.clickAndWaitForAjaxRerender(submitButtonXpathRight);
    browser.assertElementTextVisible(modelValueXpathRight, text);
    browser.assertElementVisible(immediateMessageRight);
}