List of usage examples for org.openqa.selenium WebElement sendKeys
void sendKeys(CharSequence... keysToSend);
From source file:com.github.licanhua.example.expedia.pages.CarSearchComponent.java
License:Apache License
private void fillLocationField(WebElement webElement, String location) { webElement.clear();//from w ww . j a va 2 s.c o m webElement.sendKeys(location); waitForElementToBeDisplayed(suggestionSelectComponent); suggestionSelectComponent.select(1); waitForElementToBeAbsent(suggestionSelectComponent); }
From source file:com.github.psorobka.appium.pages.AppiumExampleActivityPage.java
License:Apache License
public AppiumExampleActivityPage setName(String name) { WebElement element = driver.findElement(By.id(NAME_ID)); element.sendKeys(name); return this; }
From source file:com.gkopevski.fuelcheck.FuelCheckForm.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed try {// w w w . ja v a 2s. c o m // Create a new instance of the html unit driver // Notice that the remainder of the code relies on the interface, // not the implementation. driver = new PhantomJSDriver(); ; // And now use this to visit Google driver.get("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit(); // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.gkopevski.fuelcheck.FuelCheckForm.java
/** * This method will crawl data from a web site. When data is fetched will be * compared with the latest get data from the database; If this data is * newer it will be stored in the variable latest data which will be from * type @FuelEntry. If the new data is newer will be passed for printing and * it will be printed;/*from w ww . jav a2 s. c o m*/ * */ private void crawlData() { try { // Create a new instance of the html unit driver // Notice that the remainder of the code relies on the interface, // not the implementation. driver = new PhantomJSDriver(); System.out.println("URL: " + Constants.BASE_URL + "/" + Constants.LOGIN_HTML); driver.get(Constants.BASE_URL + "/" + Constants.LOGIN_HTML); driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); WebElement element = driver.findElement(By.id("Field__UserLogin")); element.sendKeys(Constants.USERNAME); element = driver.findElement(By.id("Field__UserPassword")); element.sendKeys(Utility.generatePassword()); element = driver.findElement(By.xpath("(//div[@id='DivMenu']/table/tbody/tr/td)[1]")); element.click(); driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); // And now use this to visit Google // driver.get(Constants.BASE_URL + "/" + Constants.OVERVIEW_HTML); // Find the text input element by its name WebElement baseTable = driver.findElement( By.xpath("(//tr[@id='__DashBoardGroup21']/td/table[@id='__DashBoardGroup21']/tbody/tr)[3]")); List<WebElement> rawEntry = baseTable.findElements(By.tagName("td")); FuelEntry tempFuelEntry = new FuelEntry(); String[] quantityUnit = rawEntry.get(8).getText().split(" "); tempFuelEntry.setQuantity(new BigDecimal(quantityUnit[0])); tempFuelEntry.setMeasurementUnit(quantityUnit[1]); SimpleDateFormat dt = new SimpleDateFormat("dd/MM/yyyyy hh:mm:ss"); Date date = dt.parse(rawEntry.get(6).getText()); if (latestFE == null || (date.after(latestFE.getStartDate()) && tempFuelEntry.getQuantity().compareTo(BigDecimal.ZERO) > 0)) { tempFuelEntry.setDriver(rawEntry.get(2).getText()); tempFuelEntry.setVehicle(rawEntry.get(3).getText()); tempFuelEntry.setProduct(rawEntry.get(4).getText()); tempFuelEntry.setDispenzer(Integer.valueOf(rawEntry.get(5).getText())); tempFuelEntry.setStartDate(date); fuelEntryService.saveFuelEntry(tempFuelEntry); latestFE = tempFuelEntry; PrintFuelEntry pfe = new PrintFuelEntry(); pfe.printLatestEntry(); } driver.quit(); } catch (Exception e) { e.printStackTrace(); } }
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();//from w w w . j a v a 2s . c om textEditView.sendKeys("this is some input"); assertEquals("this is some input", textEditView.getText()); }
From source file:com.google.appengine.tck.driver.DefaultLoginHandler.java
License:Open Source License
public void login(WebDriver driver, LoginContext context) { WebElement email = driver.findElement(By.id("email")); email.clear();// w w w . j a v a 2s. c o m email.sendKeys(context.getEmail()); if (context.isAdmin()) { driver.findElement(By.id("isAdmin")).click(); } driver.findElement(By.id("btn-login")).click(); }
From source file:com.google.appengine.tck.env.appspot.AppspotLoginHandler.java
License:Open Source License
public void login(WebDriver driver, LoginContext context) { try {//from w w w .j av a2 s.co m WebElement email = driver.findElement(By.id("Email")); if (email.getAttribute("readonly") == null) { email.clear(); email.sendKeys(context.getEmail()); } WebElement password = driver.findElement(By.id("Passwd")); password.sendKeys(context.getPassword()); driver.findElement(By.name("signIn")).click(); } catch (NoSuchElementException e) { throw new IllegalStateException( String.format("URL[%s]\n\n%s", driver.getCurrentUrl(), driver.getPageSource()), e); } }
From source file:com.google.iphone.testing.nativedriver.client.NativeDriverTest.java
License:Apache License
public void testNativeDriver() throws Exception { WebDriver driver = new IosNativeDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // Type user name WebElement userName = driver.findElement(By.placeholder("User Name")); userName.clear();//w w w . j a va 2 s .c om userName.sendKeys("NativeDriver"); // Type password WebElement password = driver.findElement(By.placeholder("Password")); password.clear(); password.sendKeys("abcdefgh"); // Tap "Sign in" button driver.findElement(By.text("Sign in")).click(); // Verify correct title is displayed String text = driver.getTitle(); assertEquals("NativeDriver", text); // Type text in WebView WebElement element = driver.findElement(By.name("q")); element.sendKeys("NativeDriver"); element.submit(); // Click link driver.findElement(By.partialLinkText("GUI automation")).click(); // Verify the page assertEquals("nativedriver", driver.findElement(By.id("pname")).getText()); }
From source file:com.googlecode.fightinglayoutbugs.DetectElementsWithInvisibleFocus.java
License:Apache License
@Nullable private FocusedElement focusFirstElement(WebPage webPage) { WebElement firstFocusedWebElement = getFocusedWebElement(webPage); if (firstFocusedWebElement == null) { // Try to focus first element ... try {//from ww w . j a v a 2s . c o m WebDriver driver = webPage.getDriver(); WebElement bodyElement = driver.findElement(By.tagName("body")); bodyElement.sendKeys(Keys.TAB); } catch (Exception e) { LOG.warn("Failed to focus first element.", e); } firstFocusedWebElement = getFocusedWebElement(webPage); } else if ("body".equals(firstFocusedWebElement.getTagName().toLowerCase())) { firstFocusedWebElement.sendKeys(Keys.TAB); firstFocusedWebElement = getFocusedWebElement(webPage); } if (firstFocusedWebElement != null && !"body".equals(firstFocusedWebElement.getTagName().toLowerCase())) { return toFocusedElement(firstFocusedWebElement, webPage); } else { return null; } }
From source file:com.googlesites.IntranetPage.java
public void addComment(String comment) { WebElement commentSection = driver.findElement(By.cssSelector(COMMENT_TEXTAREA)); commentSection.click();/*from ww w.ja va 2 s .co m*/ commentSection.sendKeys(comment); driver.findElement(By.cssSelector(POST_COMMENT)).click(); driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); assertNotNull(driver.findElement(By.xpath(POSTED_COMMENT.replace("@comment@", comment))), "The added comment is not displayed."); }