List of usage examples for org.openqa.selenium WebElement sendKeys
void sendKeys(CharSequence... keysToSend);
From source file:com.liferay.faces.test.showcase.inputtext.InputTextTester.java
License:Open Source License
protected void runInputTextConversionTest(String componentName, String inputText1Xpath, String inputText2Xpath) throws Exception { BrowserDriver browserDriver = getBrowserDriver(); navigateToUseCase(browserDriver, componentName, "conversion"); // Test that the web page shows an error message when an invalid value is submitted. WebElement input = browserDriver.findElementByXpath(inputText1Xpath); input.clear();/*from ww w .j a va 2 s . com*/ String invalidText1 = "apr 3 33"; input.sendKeys(invalidText1); browserDriver.clickElementAndWaitForRerender(submitButton1Xpath); WaitingAsserter waitingAsserter = getWaitingAsserter(); waitingAsserter.assertElementDisplayed(error1Xpath); // Test that a valid value submits successfully. input = browserDriver.findElementByXpath(inputText1Xpath); input.clear(); String text1 = "apr 3, 33"; input.sendKeys(text1); browserDriver.clickElementAndWaitForRerender(submitButton1Xpath); String textOutput1 = "Apr 3, 0033"; waitingAsserter.assertTextPresentInElement(textOutput1, modelValue1Xpath); // Test that the web page shows an error message when an invalid value is submitted. input = browserDriver.findElementByXpath(inputText2Xpath); input.clear(); String invalidText2 = "4/333"; input.sendKeys(invalidText2); browserDriver.clickElementAndWaitForRerender(submitButton2Xpath); waitingAsserter.assertElementDisplayed(error1Xpath); // Test that a valid value submits successfully. input = browserDriver.findElementByXpath(inputText2Xpath); input.clear(); String text2 = "4/3/33"; input.sendKeys(text2); browserDriver.clickElementAndWaitForRerender(submitButton2Xpath); String textOutput2 = "04/03/0033"; waitingAsserter.assertTextPresentInElement(textOutput2, modelValue2Xpath); }
From source file:com.liferay.faces.test.showcase.inputtext.InputTextTester.java
License:Open Source License
protected void runInputTextValidationTest(String componentName, String inputText1Xpath, String inputText2Xpath) throws Exception { BrowserDriver browserDriver = getBrowserDriver(); navigateToUseCase(browserDriver, componentName, "validation"); // Test that the web page shows an error message when an invalid value is submitted. WebElement input = browserDriver.findElementByXpath(inputText1Xpath); input.clear();//from w w w. ja va2 s . c om String invalidText = "HelloWorldcom"; input.sendKeys(invalidText); browserDriver.clickElementAndWaitForRerender(submitButton1Xpath); WaitingAsserter waitingAsserter = getWaitingAsserter(); waitingAsserter.assertElementDisplayed(error1Xpath); // Test that a valid value submits successfully. input = browserDriver.findElementByXpath(inputText1Xpath); input.clear(); String text = "Hello@World.com"; input.sendKeys(text); browserDriver.clickElementAndWaitForRerender(submitButton1Xpath); waitingAsserter.assertTextPresentInElement(text, modelValue1Xpath); // Test that the web page shows an error message when an invalid value is submitted. input = browserDriver.findElementByXpath(inputText2Xpath); input.clear(); input.sendKeys(invalidText); browserDriver.clickElementAndWaitForRerender(submitButton2Xpath); waitingAsserter.assertElementDisplayed(error1Xpath); // Test that a valid value submits successfully. input = browserDriver.findElementByXpath(inputText2Xpath); input.clear(); input.sendKeys(text); browserDriver.clickElementAndWaitForRerender(submitButton2Xpath); waitingAsserter.assertTextPresentInElement(text, modelValue2Xpath); }
From source file:com.liferay.faces.test.showcase.inputtext.InputTextValidationTester.java
License:Open Source License
@Test public void runInputTextValidationTest() throws Exception { Browser browser = Browser.getInstance(); browser.navigateToURL(inputTextURL + "/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 www . j a va 2 s .c om*/ 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.inputtextarea.InputTextareaConversionTester.java
License:Open Source License
@Test public void runInputTextareaConversionTest() 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 .j a va2 s . co 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.inputtextarea.InputTextareaImmediateTester.java
License:Open Source License
@Test public void runInputTextareaImmediateTest() 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);// w w w .j a va 2 s . c o m browser.clickAndWaitForAjaxRerender(submitButtonXpathRight); browser.assertElementTextVisible(modelValueXpathRight, text); browser.assertElementVisible(immediateMessageRight); }
From source file:com.liferay.faces.test.showcase.inputtextarea.InputTextareaValidationTester.java
License:Open Source License
@Test public void runInputTextareaValidationTest() throws Exception { Browser browser = Browser.getInstance(); browser.navigateToURL(inputTextURL + "/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 w w w. jav a2 s. co 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.util.TesterBase.java
License:Open Source License
public void signIn(WebDriver browser, WebElement user, WebElement pass, WebElement button, WebElement text, String textXpath, String u, String p) throws Exception { java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF); logger.log(Level.INFO, "browser.navigate().to(" + signInUrl + ")"); browser.navigate().to(signInUrl);/*from w w w . j a v a2 s . c o m*/ logger.log(Level.INFO, "browser.getTitle() = " + browser.getTitle() + " before signing in ..."); if (browser.getTitle().contains("Status")) { logger.log(Level.INFO, "welcome-theme installed ..."); String welcomeSignInUrl = signInUrl.replace("home", "welcome"); logger.log(Level.INFO, "browser.navigate().to(" + welcomeSignInUrl + ")"); browser.navigate().to(welcomeSignInUrl); logger.log(Level.INFO, "browser.getTitle() = " + browser.getTitle() + " before signing in ..."); } else { logger.log(Level.INFO, "no welcome-theme, no problem ..."); } if (isThere(browser, "//div[contains(text()[2],'was not found')]")) { // attempt to go to a Bridge Demos to get to the login page logger.log(Level.INFO, "Attempting to go to a Bridge Demos to get to the login page ..."); String bridgeDemosSignInUrl = baseUrl + "/group/bridge-demos/"; logger.log(Level.INFO, "browser.navigate().to(" + bridgeDemosSignInUrl + ")"); browser.navigate().to(bridgeDemosSignInUrl); logger.log(Level.INFO, "browser.getTitle() = " + browser.getTitle() + " before signing in ..."); waitForElement(browser, emailFieldXpath); user.clear(); user.sendKeys(u); pass.clear(); pass.sendKeys(p); button.click(); waitForElement(browser, "//span[contains(text(),'Bridge Demos')]"); return; } user.clear(); user.sendKeys(u); pass.clear(); pass.sendKeys(p); button.click(); logger.log(Level.INFO, "browser.getTitle() = " + browser.getTitle() + " after clicking the sign in button. Now waiting ..."); waitForElement(browser, textXpath); logger.log(Level.INFO, text.getText()); }
From source file:com.linagora.obm.ui.page.CreateUserPage.java
License:Open Source License
private void doCreateUser(UIUser userToCreate) { if (userToCreate.hasKindDefined()) { userKind.sendKeys(userToCreate.getKind().getUiFrenchText()); }/*from w w w. j ava 2 s.c om*/ userLogin.sendKeys(userToCreate.getLogin()); userFirstname.sendKeys(userToCreate.getFirstName()); userLastname.sendKeys(userToCreate.getLastName()); userCommonname.sendKeys(userToCreate.getCommonName()); passwd.sendKeys(userToCreate.getPassword()); userTitle.sendKeys(userToCreate.getTitle()); clickCheckbox(cba_hidden, userToCreate.isMailboxHidden()); clickCheckbox(cba_archive, userToCreate.isMailboxArchive()); delegationTargetField.sendKeys(userToCreate.getDelegation()); clickCheckbox(noexperie, !userToCreate.isNoExpire()); userPhone.sendKeys(userToCreate.getPhone()); userPhone2.sendKeys(userToCreate.getPhone2()); userMobile.sendKeys(userToCreate.getPhoneMobile()); userFax.sendKeys(userToCreate.getPhoneFax()); userFax2.sendKeys(userToCreate.getPhoneFax2()); userCompany.sendKeys(userToCreate.getCompany()); userDirection.sendKeys(userToCreate.getDirection()); userService.sendKeys(userToCreate.getService()); userAd1.sendKeys(userToCreate.getAddress1()); userAd2.sendKeys(userToCreate.getAddress2()); userAd3.sendKeys(userToCreate.getAddress3()); userZip.sendKeys(userToCreate.getAddressZip()); userTown.sendKeys(userToCreate.getAddressTown()); userCdx.sendKeys(userToCreate.getAddressCedex()); userDesc.sendKeys(userToCreate.getDescription()); if (clickCheckbox(userMailActive, userToCreate.isEmailInternalEnabled())) { WebElement firstInternalEmail = Iterables.getLast(internalEmailFields); firstInternalEmail.sendKeys(userToCreate.getEmailAddress()); } else { externalEmailField.sendKeys(userToCreate.getEmailAddress()); } SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); if (userToCreate.getDateBegin() != null) { userDatebegin.sendKeys(sdf.format(userToCreate.getDateBegin())); } if (userToCreate.getDateExpire() != null) { userDateexp.sendKeys(sdf.format(userToCreate.getDateExpire())); } for (WebElement domainOption : sel_profile.findElements(By.tagName("option"))) { if (domainOption.getAttribute("value").equals(String.valueOf(userToCreate.getProfile().getUiValue()))) { domainOption.click(); } } createUserSubmit.click(); }
From source file:com.mgmtp.jfunk.web.step.JFunkWebElement.java
License:Apache License
/** * @throws StepException//from ww w . ja va 2 s . c o m * <ul> * <li>if element specified by {@link By} object in the constructor cannot be found</li> * <li>if a validation error occurred while checking the value of the WebElement * against the desired value</li> * </ul> */ @Override public void execute() throws StepException { elementValue = retrieveElementValue(); final WebDriverWait wait = new WebDriverWait(getWebDriver(), WebConstants.DEFAULT_TIMEOUT); final WebElement element = wait.until(new Function<WebDriver, WebElement>() { @Override public WebElement apply(final WebDriver input) { List<WebElement> webElements = input.findElements(by); if (webElements.isEmpty()) { throw new StepException("Could not find any matching element; By=" + by.toString()); } /* * If the search using the By object does find more than one matching element we are * looping through all elements if we find at least one which matches the criteria * below. If not, an exception is thrown. */ for (WebElement webElement : webElements) { if (webElement.isDisplayed()) { if (webElement.isEnabled() || !webElement.isEnabled() && (stepMode == StepMode.CHECK_DEFAULT || stepMode == StepMode.CHECK_VALUE)) { return webElement; } } } throw new StepException("All elements matching by=" + by + " were either invisible or disabled"); } }); switch (stepMode) { case CHECK_DEFAULT: // Check only for text input and textarea if (element.getTagName().equals(WebConstants.INPUT) && element.getAttribute(WebConstants.TYPE).equals(WebConstants.TEXT) || element.getTagName().equals(WebConstants.TEXTAREA)) { log.info(toString()); String value = element.getAttribute(WebConstants.VALUE); if (!DataUtils.isDefaultValue(value)) { throw new ValidationException("Wrong default value=" + value + " of " + this); } } break; case CHECK_VALUE: String checkValue = elementValue; if (checkTrafo != null) { checkValue = checkTrafo.trafo(checkValue); } log.info(this + ", checkValue=" + checkValue); if (element.getTagName().equalsIgnoreCase(WebConstants.SELECT)) { Select select = new Select(element); String value = select.getFirstSelectedOption().getAttribute(WebConstants.VALUE); if (!Objects.equal(checkValue, value)) { String text = select.getFirstSelectedOption().getText(); if (!Objects.equal(checkValue, text)) { throw new InvalidValueException(element, checkValue, text + " (option value=" + value + ")"); } } } else if (WebConstants.INPUT.equalsIgnoreCase(element.getTagName()) && WebConstants.RADIO.equals(element.getAttribute(WebConstants.TYPE))) { List<WebElement> elements = getWebDriver().findElements(by); for (WebElement webElement : elements) { if (webElement.isDisplayed() && webElement.isEnabled()) { String elVal = webElement.getAttribute(WebConstants.VALUE); if (elVal.equals(checkValue) && !webElement.isSelected()) { throw new InvalidValueException(element, checkValue, elVal); } } } } else if (WebConstants.CHECKBOX.equals(element.getAttribute(WebConstants.TYPE))) { boolean elVal = element.isSelected(); if (elVal != Boolean.valueOf(checkValue)) { throw new InvalidValueException(element, checkValue, String.valueOf(elVal)); } } else { String value = element.getAttribute(WebConstants.VALUE); if (!Objects.equal(checkValue, value)) { throw new InvalidValueException(element, checkValue, value); } } break; case SET_VALUE: String setValue = elementValue; if (setTrafo != null) { setValue = setTrafo.trafo(setValue); } log.info(this + (setTrafo != null ? ", setValue (after trafo)=" + setValue : "")); if (element.getTagName().equalsIgnoreCase(WebConstants.SELECT)) { Select select = new Select(element); // First check if a matching value can be found List<WebElement> options = select.getOptions(); boolean found = false; for (WebElement option : options) { String optionValue = option.getAttribute(WebConstants.VALUE); if (StringUtils.equals(optionValue, setValue)) { /* * WebElement with matching value could be found --> we are finished */ found = true; select.selectByValue(setValue); break; } } if (!found) { /* * Fallback: look for a WebElement with a matching visible text */ for (WebElement option : options) { String visibleText = option.getText(); if (StringUtils.equals(visibleText, setValue)) { /* * WebElement with matching value could be found --> we are finished */ found = true; select.selectByVisibleText(setValue); break; } } } if (!found) { throw new StepException( "Could not find a matching option element in " + element + " , By: " + by.toString()); } } else if (WebConstants.INPUT.equalsIgnoreCase(element.getTagName()) && WebConstants.RADIO.equals(element.getAttribute(WebConstants.TYPE))) { List<WebElement> elements = getWebDriver().findElements(by); for (WebElement webElement : elements) { if (webElement.isDisplayed() && webElement.isEnabled()) { String elVal = webElement.getAttribute(WebConstants.VALUE); if (elVal.equals(setValue) && !webElement.isSelected()) { webElement.click(); } } } } else if (WebConstants.CHECKBOX.equals(element.getAttribute(WebConstants.TYPE))) { if (Boolean.valueOf(setValue) && !element.isSelected() || !Boolean.valueOf(setValue) && element.isSelected()) { element.click(); } } else { if (element.isDisplayed() && element.isEnabled() && (element.getAttribute("readonly") == null || element.getAttribute("readonly").equals("false"))) { element.clear(); element.sendKeys(setValue); } else { log.warn("Element is invisible or disabled, value cannot be set"); } } break; case NONE: // do nothing break; default: throw new IllegalArgumentException("Unhandled StepMode=" + stepMode); } }
From source file:com.mgmtp.jfunk.web.util.FormInputHandler.java
License:Apache License
/** * Tries to find the field and sets or checks its value depending on the {@link StepMode}. */// w w w. j av a2s. c om public void perform() { log.info(toString()); WebElement element = finder.find(); switch (stepMode) { case CHECK_VALUE: String checkValue = retrieveValue(); if (checkTrafo != null) { checkValue = checkTrafo.trafo(checkValue); } checkValue(element, checkValue); break; case CHECK_DEFAULT: checkState(defaultsProvider != null, "No DefaultsProvider set when StepMode is CHECK_DEFAULT."); checkValue(element, defaultsProvider.get(element, dataSet, dataKey, dataIndex)); break; case SET_VALUE: String setValue = retrieveValue(); if (setTrafo != null) { setValue = setTrafo.trafo(setValue); } if (element.getTagName().equalsIgnoreCase(WebConstants.SELECT)) { Select select = new Select(element); // First check if a matching value can be found List<WebElement> options = select.getOptions(); boolean found = false; for (WebElement option : options) { String optionValue = option.getAttribute(WebConstants.VALUE); if (StringUtils.equals(optionValue, setValue)) { /* * WebElement with matching value could be found --> we are finished */ found = true; select.selectByValue(setValue); break; } } if (!found) { /* * Fallback: look for a WebElement with a matching visible text */ for (WebElement option : options) { String visibleText = option.getText(); if (StringUtils.equals(visibleText, setValue)) { /* * WebElement with matching value could be found --> we are finished */ found = true; select.selectByVisibleText(setValue); break; } } } if (!found) { throw new JFunkException( "Could not find a matching option element in " + element + " , By: " + finder.getBy()); } } else if (WebConstants.INPUT.equalsIgnoreCase(element.getTagName()) && WebConstants.RADIO.equals(element.getAttribute(WebConstants.TYPE))) { List<WebElement> elements = finder.findAll(); for (WebElement webElement : elements) { String elVal = webElement.getAttribute(WebConstants.VALUE); if (elVal.equals(setValue) && !webElement.isSelected()) { webElement.click(); } } } else if (WebConstants.CHECKBOX.equals(element.getAttribute(WebConstants.TYPE))) { if (Boolean.valueOf(setValue) && !element.isSelected() || !Boolean.valueOf(setValue) && element.isSelected()) { element.click(); } } else { if (element.getAttribute("readonly") == null || element.getAttribute("readonly").equals("false")) { element.clear(); element.sendKeys(setValue); } else { log.warn("Element is invisible or disabled, value cannot be set"); } } break; case NONE: // do nothing break; default: throw new IllegalArgumentException("Unhandled StepMode=" + stepMode); } }