List of usage examples for org.openqa.selenium WebElement clear
void clear();
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Sets the value./*from ww w .ja va2 s. c o m*/ * @param driver the driver * @param id the id * @param value the value */ public static void setValue(WebDriver driver, String id, String value) { if (isDisplayedById(driver, id, 10)) { WebElement input = driver.findElement(By.id(id)); input.clear(); input.sendKeys(value); } }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Clear and input.//www .j a v a2 s . c om * @param driver the driver * @param locator the locator * @param fieldValue the field value */ public static void clearAndInput(final WebDriver driver, final By locator, final String fieldValue) { final WebElement element = driver.findElement(locator); element.clear(); element.sendKeys(fieldValue); }
From source file:com.example.getstarted.basicactions.UserJourneyTestIT.java
License:Apache License
private void login(String email) { WebElement input = driver.findElement(By.cssSelector("input[type=text]")); input.clear(); input.sendKeys(email);/* w ww . j a va 2 s . c o m*/ input.submit(); }
From source file:com.fmb.common.BrowserEmulator.java
License:Apache License
/** * Type text at the page element<br> * Before typing, try to clear existed text * @param xpath/*w w w.ja va2 s. c o m*/ * the element's xpath * @param text * the input text */ public void type(String xpath, String text) { pause(stepInterval); expectElementExistOrNot(true, xpath, timeout); WebElement we = browserCore.findElement(By.xpath(xpath)); try { we.clear(); } catch (Exception e) { logger.warn("Failed to clear text at " + xpath); } try { we.sendKeys(text); } catch (Exception e) { e.printStackTrace(); handleFailure("Failed to type " + text + " at " + xpath); } logger.info("Type " + text + " at " + xpath); }
From source file:com.formkiq.web.WorkflowEditorControllerIntegrationTest.java
License:Apache License
/** * Edits Field./* w ww . j ava 2 s. c om*/ * * @param fieldid {@link String} * @param values {@link Map} * @throws InterruptedException InterruptedException */ private void editField(final String fieldid, final Map<String, String> values) throws InterruptedException { clickEditFieldButton(fieldid); getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("fieldeditorform"))); for (Map.Entry<String, String> e : values.entrySet()) { String field = e.getKey(); String value = e.getValue(); By by = By.xpath("//*[self::textarea|self::input|self::select|self::button]" + "[@data-fieldid='" + field + "']"); WebElement element = findElementBy(by); assertTrue(element.isDisplayed()); String tagname = element.getTagName(); switch (tagname) { case "select": Select select = new Select(element); waitUntilSelectOptionsPopulated(select); select.selectByVisibleText(extractLabelAndValue(value).getLeft()); break; case "button": element.click(); break; default: element.clear(); element.sendKeys(value); break; } } //findElementBy(By.className("form-modal-update-button")).click(); click(By.name("_eventId_next")); getWait().until(ExpectedConditions.invisibilityOfElementLocated(By.id("fieldeditorform"))); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlElement2Test.java
License:Apache License
/** * @throws Exception if the test fails/* ww w .j a v a 2 s . c o m*/ */ @Test @NotYetImplemented //TODO: fails because of HTMLElement.getContentEditable doesn't detect DomElement.ATTRIBUTE_VALUE_EMPTY // this could be a general attribute issue public void contentEditable() throws Exception { final String html = "<html>\n" + "<body contentEditable><p>initial</p></body>\n" + "</html>"; final WebDriver driver = loadPage2(html); final WebElement body = driver.findElement(By.xpath("//body")); body.clear(); body.sendKeys("something"); assertEquals("something", body.getText()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlInput2Test.java
License:Apache License
private void testClickEventSequence(final String input, final boolean onClickRetFalse) throws Exception { final String events = " onmousedown=\"log('mousedown')\" onmouseup=\"log('mouseup')\" " + "onfocus=\"log('onfocus')\" onchange=\"log('onchange')\" " + "onclick=\"log('onclick')\""; String tag = StringUtils.replaceOnce(input, ">", events + ">"); if (onClickRetFalse) { tag = StringUtils.replaceOnce(tag, "onclick')", "onclick');return false;"); }/* w ww. j a va 2 s . co m*/ final String html = "<html><head>\n" + "<script>\n" + " function log(x) {\n" + " document.getElementById('log_').value += x + '; ';\n" + " }\n" + "</script>\n" + "</head>\n<body>\n" + "<form>\n" + " <textarea id='log_' rows='4' cols='50'></textarea>\n" + tag + "\n" + " <input type='text' id='next'>\n" + "</form>\n" + "</body></html>"; final List<String> alerts = new LinkedList<>(); final WebDriver driver = loadPage2(html); final WebElement log = driver.findElement(By.id("log_")); driver.findElement(By.id(TEST_ID)).click(); alerts.add(log.getAttribute("value").trim()); log.clear(); driver.findElement(By.id("next")).click(); alerts.add(log.getAttribute("value").trim()); assertEquals(getExpectedAlerts(), alerts); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLInputElementTest.java
License:Apache License
/** * @throws Exception if the test fails/*from w ww. j a va 2 s . c o m*/ */ @Test public void clear() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>foo</title><script>\n" + "</script></head>\n" + "<body>\n" + " <input id='myInput' value='Test' onchange=\"alert('changed')\">\n" + "</body></html>"; final WebDriver driver = loadPageWithAlerts2(html); final WebElement element = driver.findElement(By.id("myInput")); element.clear(); verifyAlerts(driver, "changed"); }
From source file:com.github.licanhua.example.expedia.pages.CarSearchComponent.java
License:Apache License
private void fillLocationField(WebElement webElement, String location) { webElement.clear(); webElement.sendKeys(location);/*from ww w .j av a 2 s. c o m*/ waitForElementToBeDisplayed(suggestionSelectComponent); suggestionSelectComponent.select(1); waitForElementToBeAbsent(suggestionSelectComponent); }
From source file:com.google.android.testing.nativedriver.TextValueTest.java
License:Apache License
public void testTextValue() { driver.startActivity("com.google.android.testing.nativedriver" + ".simplelayouts.TextValueActivity"); WebElement textView = driver.findElement(By.id("TextView01")); assertEquals("Hello, Android NativeDriver!", textView.getText()); WebElement textEditView = driver.findElement(By.id("EditText01")); textEditView.clear(); textEditView.sendKeys("this is some input"); assertEquals("this is some input", textEditView.getText()); }