List of usage examples for org.openqa.selenium WebElement clear
void clear();
From source file:be.rubus.web.jerry.validation.CustomTest.java
License:Apache License
@Test @RunAsClient/*from w w w. j a v a 2 s .c o m*/ public void testCustom() throws Exception { driver.get(new URL(contextPath, "custom.xhtml").toString()); WebElement element = driver.findElement(By.id("test:zipCodeMaskLabel")); String text = element.getText(); assertThat(text).isEqualTo("Zip code (mask)*"); element = driver.findElement(By.id("test:zipCode")); assertThat(element.getAttribute("maxlength")).isEqualTo("4"); element = driver.findElement(By.id("test:zipCodeMask")); element.sendKeys("azer"); // Only numbers allowed in the mask assertThat(element.getAttribute("value")).isEqualTo("____"); element.clear(); element.sendKeys("12345"); // Only 4 numbers allowed in the mask assertThat(element.getAttribute("value")).isEqualTo("1234"); }
From source file:be.rubus.web.jerry.validation.FutureDateProviderTest.java
License:Apache License
@Test @RunAsClient/*w ww . j a va2 s. c o m*/ public void testFuture() throws Exception { driver.get(new URL(contextPath, "future.xhtml").toString()); //By default, the date provider is using system date, so failures WebElement date1 = driver.findElement(By.id("test:date1")); date1.sendKeys("23/02/2015"); WebElement date2 = driver.findElement(By.id("test:date2")); date2.sendKeys("23/02/2015"); assertThat(date1.getAttribute("class")).doesNotContain("ui-state-error"); assertThat(date2.getAttribute("class")).doesNotContain("ui-state-error"); WebElement btn = driver.findElement(By.id("test:submit")); btn.click(); WebElement errors = driver.findElement(By.id("errors")); List<WebElement> errorMessages = errors.findElements(By.tagName("li")); assertThat(errorMessages).hasSize(2); // Page is reloaded so elements are detached date1 = driver.findElement(By.id("test:date1")); date2 = driver.findElement(By.id("test:date2")); assertThat(date1.getAttribute("class")).contains("ui-state-error"); assertThat(date2.getAttribute("class")).contains("ui-state-error"); // Set date for DateProvider WebElement fixedNow = driver.findElement(By.id("date:fixedNow")); fixedNow.clear(); fixedNow.sendKeys("20/02/2015"); WebElement dateBtn = driver.findElement(By.id("date:setDate")); dateBtn.click(); date1 = driver.findElement(By.id("test:date1")); date1.sendKeys("23/02/2015"); date2 = driver.findElement(By.id("test:date2")); date2.sendKeys("23/02/2015"); btn = driver.findElement(By.id("test:submit")); btn.click(); errors = driver.findElement(By.id("errors")); errorMessages = errors.findElements(By.tagName("li")); assertThat(errorMessages).hasSize(1); // Only 1 error now // Page is reloaded so elements are detached date1 = driver.findElement(By.id("test:date1")); date2 = driver.findElement(By.id("test:date2")); assertThat(date1.getAttribute("class")).contains("ui-state-error"); assertThat(date2.getAttribute("class")).doesNotContain("ui-state-error"); // The one withValFuture }
From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.primefaces.PrimefacesGrid.java
License:Open Source License
@Override public void tableTextSendKeys(String value, String l, String c, Element element) { String xpathTabela = preparaXPath(element, l, c); String xpathTabelaBase = xpathTabela; xpathTabela = xpathTabela.concat("//textarea"); xpathTabela = xpathTabela.concat("|"); xpathTabela = xpathTabela.concat(xpathTabelaBase); xpathTabela = xpathTabela.concat("//input[@type='text']"); WebElement myElement = (WebElement) ((WebDriver) runner.getDriver()).findElement(By.xpath(xpathTabela)); myElement.clear(); myElement.sendKeys(value);// ww w . ja va2 s.c om }
From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.WebAutoComplete.java
License:Open Source License
/** * Mtodo generalizado para selecionar o valor da lista * /* w w w . j a v a 2s.co m*/ * @param value Valor a ser informado no campo de texto do autocomplete */ protected void select(String value) { // Aguarda o primeiro elemento ser clicvel waitElement(0); List<WebElement> elements = getElements(); if (elements.size() == 1 && getElementMap().locator().length == 1) { throw new BehaveException( message.getString("exception-autocomplete-missing-elements", "locator", "@ElementMap")); } WebElement element = elements.get(0); if (element.getTagName().equals("input") && element.getAttribute("type").equals("text")) { // Preenche o valor do Autocomplete element.clear(); element.sendKeys(value); } /* * Tempo do efeito de abertura das opes * * Obs: Utilizada API de Reflection para retrocompatibilidade * com verses anteriores do DBehave (1.3.0 por exemplo) */ try { Method waitElementOnlyVisible = getClass().getMethod("waitElementOnlyVisible", new Class[] { Integer.class }); try { waitElementOnlyVisible.invoke(this, new Object[] { 1 }); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (NoSuchMethodException e) { waitElement(1); } if (this.selectValue != null) { value = this.selectValue; } selectOnList(elements.get(1), value); }
From source file:br.ufmg.dcc.saotome.beholder.selenium.WebElementAdapter.java
License:Apache License
@Override public void clear() { (new StaleExceptionResolver<Object>() { @Override// www . j a va 2 s . co m public Object execute(WebElement element) { element.clear(); return null; } }).waitForElement(); }
From source file:bst.cpo.automation.dm.actions.SystemOverview_Actions.java
public void Set_User(String strUser) { //<input type="text" ng-model="pp.query" maxlength="60" required="" class="ng-dirty ng-invalid ng-invalid-required"> WebElement element = DMDriver .findElement(By.xpath("//*[@id='app']/div/div[4]/div/div/div[2]/div[1]/div[1]/form/input[1]")); element.click();/*from w ww. j a v a 2s . c o m*/ element.clear(); element.sendKeys(strUser); }
From source file:ca.nrc.cadc.web.selenium.AbstractTestWebPage.java
License:Open Source License
protected void clearTextInput(final By by) throws Exception { final WebElement inputElement = waitUntil(ExpectedConditions.presenceOfElementLocated(by)); // Focus issues. hover(by);/*from w ww.java 2 s . co m*/ inputElement.click(); inputElement.clear(); }
From source file:ca.nrc.cadc.web.selenium.AbstractTestWebPage.java
License:Open Source License
public void sendKeys(final WebElement webElement, final String value) throws Exception { webElement.clear(); webElement.sendKeys(Keys.BACK_SPACE); webElement.sendKeys(value);/*from ww w.ja v a 2 s. c o m*/ }
From source file:CartTest.CartTest.java
@Test public void changeQuantity() { this.addItemIntoCart(); WebElement itemQuantity = driver.findElement( By.xpath("//*[@id=\"checkout_page_container\"]/div[1]/table/tbody/tr[2]/td[3]/form/input[1]")); itemQuantity.clear();//clear the quantity input bar itemQuantity.sendKeys("10");//change the quantity into 10 driver.findElement(//from www. j a va 2 s . c o m By.xpath("//*[@id=\"checkout_page_container\"]/div[1]/table/tbody/tr[2]/td[3]/form/input[4]")) .click();//press "change" button driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);// wait assertEquals(driver .findElement( By.xpath("//*[@id=\"checkout_page_container\"]/div[1]/table/tbody/tr[2]/td[5]/span/span")) .getText(), "$120.00");// the total price should become to "120" }
From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java
public void enterDealerName(String dealerNameString) throws Throwable { WebElement dealerName = driver.findElement(By.xpath( "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[1]/div[1]/div/input")); dealerName.clear(); dealerName.sendKeys(dealerNameString); }