List of usage examples for org.openqa.selenium WebElement clear
void clear();
From source file:com.vilt.minium.impl.actions.FillInteraction.java
License:Apache License
@Override protected void doPerform() { WebElement elem = getFirstElement(); elem.clear(); elem.sendKeys(text); }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Sets the value of an input field, as though you typed it in.<br> * Can also be used to set the value of comboboxes, check boxes, etc. In * these cases, value should be the value of the option selected, not the * visible text.<br>/*from w w w .ja va 2s . co m*/ * <br> * * @param locator * : Logical name of the web element assigned by the automation * scripter * @param objValue * the obj value */ public final void doType(final ObjectLocator locator, final Object objValue) { String value = checkNullObject(objValue, "TYPE"); int counter = getRetryCount(); // Getting the actual object identification from the object map String objectID = locator.getActualLocator(); try { // Check whether the element present checkForNewWindowPopups(); WebElement element = checkElementPresence(objectID); /* * START DESCRIPTION following for loop was added to make the * command more consistent try the command for give amount of time * (can be configured through class variable RETRY) command will be * tried for "RETRY" amount of times or until command works. any * exception thrown within the tries will be handled internally. * * can be exited from the loop under 2 conditions 1. if the command * succeeded 2. if the RETRY count is exceeded */ try { element.clear(); } catch (Exception e) { e.printStackTrace(); } while (counter > 0) { try { counter--; // Calling the actual command element.sendKeys(value); reportresult(true, "TYPE :" + locator.getLogicalName() + "", "PASSED", " [Input value = " + value + "]"); break; } catch (StaleElementReferenceException staleElementException) { element = checkElementPresence(objectID); } catch (Exception e) { sleep(retryInterval); if (!(counter > 0)) { e.printStackTrace(); String objectName = locator.getLogicalName(); reportresult(true, "TYPE :" + objectName + "", "FAILED", "TYPE command cannot access :Element (" + objectName + ") [" + objectID + "]" + " [Input value = " + value + "]"); checkTrue(false, true, "TYPE command cannot access :Element (" + objectName + ") [" + objectID + "]" + " [Input value = " + value + "]"); } } } /* * END DESCRIPTION */ } catch (Exception e) { // if any exception was raised, report a test failure e.printStackTrace(); String objectName = locator.getLogicalName(); reportresult(true, "TYPE :" + objectName + "", "FAILED", "TYPE command :Element (" + objectName + ") [" + objectID + "] [Input value = " + value + "] not present"); checkTrue(false, true, "TYPE command :Element (" + objectName + ") [" + objectID + "] [Input value = " + value + "] not present"); } }
From source file:com.westconcomster.MO365.java
public void mo365Order(WebDriver driver, String region) throws InterruptedException { String winHandleBefore = driver.getWindowHandle(); Thread.sleep(10000);/*from w ww . j a v a 2s . com*/ driver.findElement(By.xpath("//p[contains(.,'Buy Now')]")).click(); //Select the customer for (String winHandle : driver.getWindowHandles()) { driver.switchTo().window(winHandle); System.out.println(">>>>>>>>>>inside child window"); //Search for the customer Thread.sleep(5000); WebElement searchCust = driver.findElement(By.xpath("(.//*[@id='search_value'])[4]")); searchCust.clear(); searchCust.sendKeys(Constants.companyName); Thread.sleep(5000); driver.findElement(By.xpath( ".//*[@id='customersList']/div[1]/ul/div[1]/div/div[2]/div/ecommerceselectable-customer/div/div[3]/div")) .click(); //Select MO365 WebElement searchProduct = driver.findElement(By.xpath("(.//*[@id='search_value'])[5]")); searchProduct.clear(); searchProduct.sendKeys("MO365"); Thread.sleep(2000); driver.findElement(By.xpath("//ecommerceselectable-product/div/div[3]/div/p")).click(); (new WebDriverWait(driver, 60)) .until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@name='quoteName']"))) .sendKeys("LATAM_MO365_Order"); Select dropdown = new Select(driver.findElement(By.name("root[contract][supportLevel]"))); dropdown.selectByIndex(1); //Add reseller Margin driver.findElement(By.name("root[contract][resellermargin]")).clear(); driver.findElement(By.name("root[contract][resellermargin]")).sendKeys("10"); System.out.println(">>>>>>>Reseller Margin Added"); driver.findElement(By.name("root[contract][billenduser]")).click(); System.out.println(">>>>>>>>Bill End User"); JavascriptExecutor jse = (JavascriptExecutor) driver; jse.executeScript("window.scrollBy(0,350)", ""); Thread.sleep(5000); //select license MO365Licences mo365lic = new MO365Licences(); mo365lic.mo365Licences(driver, region); //Select MO365 Add-ons MO365AddOns moadd = new MO365AddOns(); moadd.mo365AddOns(driver, region); //Select Westcon Services MO365WestconServices mo365WS = new MO365WestconServices(); mo365WS.mo365WestconServices(driver, region); //Total price WebElement price = (new WebDriverWait(driver, 60)).until( ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[text()[contains(.,'Total:')]]"))); String totalAmt = price.getText().substring(price.getText().indexOf(":") + 1).trim(); System.out.println(">>>>>>>>>>>TotalAmount" + totalAmt); //Click Next Button (new WebDriverWait(driver, 20).until( ExpectedConditions.visibilityOfElementLocated(By.xpath(".//button[contains(text(),'Next')]")))) .click(); Thread.sleep(10000); driver.findElement(By.xpath(".//button[contains(text(),'Submit Order')]")).click(); //Add domain WebElement domain1 = (new WebDriverWait(driver, 30).until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//input[@name='root[microsoft_info][domain_prefix]']")))); domain1.sendKeys(Constants.domian); domain1.sendKeys(Keys.TAB); Thread.sleep(10000); //Click on Submit Order WebElement submit = (new WebDriverWait(driver, 20).until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//button[contains(text(),'Submit Order')]")))); submit.click(); System.out.println(">>>>>>>>Order Submitted "); Thread.sleep(10000); //PO Number String orderNumber = driver.findElement(By.xpath(".//ecommercewizardstep[4]/section/div/div[2]/p")) .getText().replaceAll("\\D", "").trim(); ; System.out.println(">>>>>>>>>>>Order number" + orderNumber); //Click on Close Button driver.findElement(By.xpath("//ecommercewizardstep[4]/section/div/div[2]/article/button[2]")).click(); driver.switchTo().window(winHandleBefore); //*******Verify Order on Portal Thread.sleep(10000); String orderScreenOrder = driver.findElement(By.xpath( ".//*[@id='orders']/div/section[2]/div[1]/div[2]/div/div[2]/div/order/div[1]/div/div[1]/div[3]/div/div[1]/div[2]/div[2]")) .getText(); System.out.println(">>>>>>>>>> OrderID" + orderScreenOrder); if (orderScreenOrder.equals(orderNumber)) { System.out.println(">>>>>> PASS <<<<<<< MO365 Order Created Successfully on portal"); } else { System.out.println("Order FAILED"); } } }
From source file:com.westconcomster.MO365WestconServices.java
public void mo365WestconServices(WebDriver driver, String region) throws InterruptedException { if (region.equals("BR")) { driver.findElement(By.xpath(/*from ww w . ja v a2 s. co m*/ ".//select[@name='root[product][licenses][westconProfessionalServices][WestconMobility][include]']")) .click(); WebElement wsP1 = driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconProfessionalServices][WestconMobility][include]']/option[1]")); wsP1.sendKeys("YES"); Thread.sleep(1000); driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconProfessionalServices][WestconCriptografia][include]']")) .click(); WebElement wsP2 = driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconProfessionalServices][WestconCriptografia][include]']/option[1]")); wsP2.sendKeys("YES"); Thread.sleep(1000); driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconProfessionalServices][WestconSolutionPack][include]']")) .click(); WebElement wsP3 = driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconProfessionalServices][WestconSolutionPack][include]']/option[1]")); wsP3.sendKeys("YES"); Thread.sleep(1000); driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconProfessionalServices][WestconE-mailMigration(IMAP)][include]']")) .click(); WebElement wsP4 = driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconProfessionalServices][WestconE-mailMigration(IMAP)][include]']/option[1]")); wsP4.sendKeys("YES"); Thread.sleep(1000); driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconProfessionalServices][WestconE-mailMigration(Exchange)][include]']")) .click(); WebElement wsP5 = driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconProfessionalServices][WestconE-mailMigration(Exchange)][include]']/option[1]")); wsP5.sendKeys("YES"); Thread.sleep(1000); driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconProfessionalServices][WestconProjetosEspeciais(HorasComerciais)-Bundle5horas][include]']")) .click(); WebElement wsP6 = driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconProfessionalServices][WestconProjetosEspeciais(HorasComerciais)-Bundle5horas][include]']/option[1]")); wsP6.sendKeys("YES"); Thread.sleep(1000); driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconProfessionalServices][WestconProjetosEspeciais(HorasNoComerciais)-Bundle5horas][include]']")) .click(); WebElement wsP7 = driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconProfessionalServices][WestconProjetosEspeciais(HorasNoComerciais)-Bundle5horas][include]']/option[1]")); wsP7.sendKeys("YES"); Thread.sleep(1000); /* //Qty field driver.findElement(By.xpath("//input[@name='root[product][licenses][westconProfessionalServices][WestconProjetosEspeciais(HorasNoComerciais)-Bundle5horas][licenses]']")).sendKeys(Keys.TAB); Thread.sleep(1000); System.out.println(">>>>>>Westcon Managed services selected"); */ //Checkboxes WebElement chk = (new WebDriverWait(driver, 60).until(ExpectedConditions.visibilityOfElementLocated(By .xpath(".//input[@name='root[product][licenses][westconProfessionalServices][EmailservicesAddons][WestconIntranet]']")))); chk.click(); WebElement chk2 = driver.findElement(By.xpath( ".//input[@name='root[product][licenses][westconProfessionalServices][EmailservicesAddons][WestconADSync]']")); chk2.click(); Thread.sleep(1000); WebElement chk3 = driver.findElement(By.xpath( ".//input[@name='root[product][licenses][westconProfessionalServices][EmailservicesAddons][WestconFederationServer]']")); chk3.click(); Thread.sleep(1000); WebElement chk4 = driver.findElement(By.xpath( ".//input[@name='root[product][licenses][westconProfessionalServices][EmailservicesAddons][WestconOffice365Setup]']")); chk4.click(); Thread.sleep(1000); driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconManagedServices][WestconControleMobility(monthly)][include]']")) .click(); WebElement wsP8 = driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconManagedServices][WestconControleMobility(monthly)][include]']/option[1]")); wsP8.sendKeys("YES"); Thread.sleep(1000); driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconManagedServices][WestconControleCriptografia(monthly)][include]']")) .click(); WebElement wsP9 = driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconManagedServices][WestconControleCriptografia(monthly)][include]']/option[1]")); wsP9.sendKeys("YES"); Thread.sleep(1000); driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconManagedServices][WestconControleSolutionPack(monthly)][include]']")) .click(); WebElement wsP10 = driver.findElement(By.xpath( ".//select[@name='root[product][licenses][westconManagedServices][WestconControleSolutionPack(monthly)][include]']/option[1]")); wsP10.sendKeys("YES"); System.out.println(">>>>>>>>>>>> Westcon Services added"); } else if (region.equals("CO")) { driver.findElement( By.xpath(".//input[@name='root[product][licenses][addons][o365AdministrationServicesS]']")) .click(); driver.findElement( By.xpath(".//input[@name='root[product][licenses][addons][o365AdministrationServicesM]']")) .click(); driver.findElement( By.xpath(".//input[@name='root[product][licenses][addons][o365AdministrationServicesL]']")) .click(); driver.findElement(By.xpath(".//input[@name='root[product][licenses][addons][o365MSO365Migra-S]']")) .click(); driver.findElement(By.xpath(".//input[@name='root[product][licenses][addons][o365MSO365Migra-M]']")) .click(); driver.findElement(By.xpath(".//input[@name='root[product][licenses][addons][o365MSO365Migra-L]']")) .click(); System.out.println(">>>>>>>>>>>> Westcon Services added"); } else if (region.equals("NA") || region.equals("ZA")) { //Select Westcon Services driver.findElement(By.xpath( ".//input[@name='root[product][licenses][westconProfessionalServices][SoftwareAssetManagementAssessment]']")) .click(); WebElement wsNAZA1 = driver.findElement(By.xpath( ".//input[@name='root[product][licenses][westconProfessionalServices][Office365Migrationsperseat-Dataonly]']")); wsNAZA1.clear(); wsNAZA1.sendKeys("1"); Thread.sleep(1000); WebElement wsNAZA2 = driver.findElement(By.xpath( ".//input[@name='root[product][licenses][westconProfessionalServices][Office365Migrationsperseat-Suite]']")); wsNAZA2.clear(); wsNAZA2.sendKeys("1"); Thread.sleep(1000); WebElement wsNAZA3 = driver.findElement(By.xpath( ".//input[@name='root[product][licenses][westconProfessionalServices][Office365ConfigurationandSupportforNewAccounts]']")); wsNAZA3.clear(); wsNAZA3.sendKeys("1"); Thread.sleep(1000); WebElement wsNAZA4 = driver.findElement(By.xpath( ".//input[@name='root[product][licenses][westconProfessionalServices][ExchangeOnlineConfigurationandSupportforNewAccounts]']")); wsNAZA4.clear(); wsNAZA4.sendKeys("1"); Thread.sleep(1000); System.out.println(">>>>>>>>>>>> Westcon Services added"); } else if (region.equals("MX")) { System.out.println("MX Has no Westcon Services so clicking on Next button"); } }
From source file:com.worldline.easycukes.selenium.pages.Page.java
License:Open Source License
/** * Send text keys to the element that finds by selector. * * @param by selector to find the element * @param text// ww w. j a va 2s . c om */ public void sendText(By by, @NonNull String text) { final WebElement element = getWebElement(by); if ("text".equalsIgnoreCase(element.getAttribute("type"))) element.clear(); element.sendKeys(text); }
From source file:com.zutubi.pulse.acceptance.SeleniumBrowser.java
License:Apache License
/** * Types the given value into a text field or area. Any existing text is * cleared first./*from w ww . j a v a2 s .com*/ * * @param by locator of the text field/area * @param value the text to type */ public void type(By by, String value) { WebElement element = webDriver.findElement(by); element.clear(); element.sendKeys(value); }
From source file:common.KeywordBase.java
License:Apache License
/** * Type into text box or upload files if element type = file * //w w w .j a v a2 s. com * @param locator * HTML element locator from Object Repository file. * @param value * Value * @param index * (Optional) Index of an element. Applies only if more than 1 * element present in HTML. 0 by default. */ public synchronized void type(String locator, String value, String... index) { log.info("Typing " + value); WebElement e = getElement(locator, index); e.clear(); e.sendKeys(getString(value)); }
From source file:cucumber.scratch.maven.react.pages.Finder.java
License:Apache License
public void setTextByLabel(String labelName, String text) { final WebElement input = findByLabel(labelName); input.clear(); input.sendKeys(text);/*from w ww .j a v a2s. co m*/ }
From source file:de.akquinet.devops.test.ui.view.RepoEditView.java
License:Apache License
public void changeName(String newName) { String pathName = "//input[@id = \"name\" ]"; WebElement field = getDriver().findElement(By.xpath(pathName)); field.clear(); field.sendKeys(newName);// ww w . j ava 2 s. co m }
From source file:de.betterform.conformance.WebDriverTestFunctions.java
License:BSD License
public void typeInput(String id, String value, boolean incremental) { WebElement webElement = webDriver.findElement(By.id(id)); if (!incremental) { webElement.clear(); webElement.click();/*from www . j a v a 2 s . c o m*/ } webElement.sendKeys(value); //Step out of control if (!incremental && id.contains("-value")) { WebElement parent = webDriver.findElement(By.id(id.substring(0, id.indexOf("-value")))); parent.click(); } }