Example usage for org.openqa.selenium WebElement sendKeys

List of usage examples for org.openqa.selenium WebElement sendKeys

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement sendKeys.

Prototype

void sendKeys(CharSequence... keysToSend);

Source Link

Document

Use this method to simulate typing into an element, which may set its value.

Usage

From source file:com.mycompany.firstmavenproject.command.SendKeysCommand.java

@Override
public void execute(Object driverObject) {
    WebElement we = (WebElement) driverObject;
    we.sendKeys(param);
}

From source file:com.mycompany.myproject.sample.simple.DemoMobileTest.java

License:Apache License

@Test
@MobileTest(appPath = TEST_APP_PATH, device = "android:19")
public void testNative() {
    RemoteWebDriver driver = Grid.driver();
    WebDriverWaitUtils.waitUntilElementIsVisible("io.selendroid.testapp:id/my_text_field");
    SeLionReporter.log("Main page", true, true);
    WebElement textField = driver.findElement(By.id("io.selendroid.testapp:id/my_text_field"));
    assertEquals("true", textField.getAttribute("enabled"));
    textField.sendKeys("Appium Android Native Test");
    SeLionReporter.log("Entered text", true, true);
    assertEquals("Appium Android Native Test", textField.getText());
}

From source file:com.mycompany.myselion.sample.selion.AppiumAndroidDemoTest.java

License:Apache License

/**
 * This test demonstrates how to use SeLion for running tests against a Native ANDROID app using appium.
 * <ul>//from w  w  w.j ava2s .  co  m
 * <li>
 * An appium instance/server should be locally installed and running and point SeLion to this server using any of the following options. 
 * <ol>
 * <li>Through the JVM arguments -DSELION_SELENIUM_HOST and -DSELION_SELENIUM_PORT </li> (or)
 * <li>Through suite file &lt;parameter name="seleniumhost" value=""/&gt; and &lt;parameter name="seleniumport" value=""/&gt;</li>
 * </ol></li>
 * <li>
 * For setting up Appium Android refer http://appium.io/slate/en/master/?ruby#system-setup-(android)
 * </li>
 * </ul>
 */
@Test
@MobileTest(appPath = "src/test/resources/apps/selendroid-test-app-0.15.0.apk", device = "android:5.0.1", deviceType = "Android Emulator")
public void testWithNativeApp() {
    RemoteWebDriver driver = Grid.driver();
    WebDriverWaitUtils.waitUntilElementIsVisible("io.selendroid.testapp:id/my_text_field");
    WebElement textField = driver.findElement(By.id("io.selendroid.testapp:id/my_text_field"));
    assertEquals("true", textField.getAttribute("enabled"));
    textField.sendKeys("Appium Android Native Test");
    assertEquals("Appium Android Native Test", textField.getText());
}

From source file:com.mycompany.myselion.sample.selion.AppiumAndroidDemoTest.java

License:Apache License

/**
 * This test demonstrates how to use SeLion for running tests against ANDROID browser using appium.
 * <ul>/*from   w w w.j a v  a  2  s .co  m*/
 * <li>
 * An appium instance/server should be installed and running where selenium host and port should be 
 * pointed to this instance.</li>
 * <li>
 * For setting up Appium Android refer http://appium.io/slate/en/master/?ruby#system-setup-(android)
 * </li>
 * </ul> 
 */
@Test
@MobileTest(appName = "Browser", device = "android:5.0.1", deviceType = "Android Emulator")
public void testWithBrowser() {
    RemoteWebDriver driver = Grid.driver();
    assertNotNull(driver);
    // 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();
    SeLionReporter.log("cheese!", true);
}

From source file:com.mycompany.myselion.sample.selion.AppiumAndroidSeLionHubTest.java

License:Apache License

/**
 * This test demonstrates how to use SeLion for running tests against a Native ANDROID app using appium 
 * and apps placed in selion hub storage. 
 * <ul>/*from w  ww . ja v a2s .c  o  m*/
 * <li>
 * An instance of selion grid should be spawned and the appium instance should be registered to this grid.</li>
 * <li>
 * The app selendroid-test-app-0.14.0.apk to be tested should be uploaded to SeLion hub storage 
 * provided by SeLion grid.</li>
 * <li>
 * The format of the appPath for the apps in the SeLion hub storage is as follows 
 * selion-hub-storage:{user-guid}:{folderName}:{file} where user-guid is a random unique guid and it is mandatory 
 * while uploading a file. foldername is an optional parameter and this test case is configured without folder name.</li>
 * </ul>
 */
@Test
@MobileTest(appPath = "selion-hub-storage:guid:selendroid-test-app-0.15.0.apk", device = "android:5.0.1", deviceType = "Android Emulator")
public void testWithNativeAppWithSelionHub() {
    RemoteWebDriver driver = Grid.driver();
    WebDriverWaitUtils.waitUntilElementIsVisible("io.selendroid.testapp:id/my_text_field");
    WebElement textField = driver.findElement(By.id("io.selendroid.testapp:id/my_text_field"));
    assertEquals("true", textField.getAttribute("enabled"));
    textField.sendKeys("Appium Android Native Test");
    assertEquals("Appium Android Native Test", textField.getText());
}

From source file:com.mycompany.myselion.sample.selion.AppiumIOSDemoTest.java

License:Apache License

/**
 * This test demonstrates how to use SeLion for running tests against IOS safari using appium.
 * <ul>// ww  w.jav  a  2s .  c  o m
 * <li>
 * An appium instance/server should be installed and running where selenium host and port should be 
 * configured to the same appium instance.</li> 
 * <li>
 * For setting up Appium iOS refer http://appium.io/slate/en/master/?ruby#system-setup-(ios)
 * </li>
 * </ul>
 */
@Test
@MobileTest(appName = "safari", device = "iphone:8.1", deviceType = "iPhone Simulator")
public void testWithSafari() {
    //To gain access to the IOSRemoteWebDriver, we use the thread safe helper method Grid.driver() which provides
    //an instance of IOSRemoteWebDriver for the current Test method. 
    RemoteWebDriver driver = Grid.driver();
    assertNotNull(driver);
    // 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();
    // take a screenshot
    SeLionReporter.log("cheese!", true);
}

From source file:com.mycompany.myselion.sample.selion.AppiumSauceCloudTest.java

License:Apache License

/**
 * This test demonstrates how to use SeLion for running tests against a Native ANDROID app in sauce cloud.
 * This selendroid-test-app-0.15.0.apk must be uploaded to sauce temporary storage before running this test case.
 *///from ww  w .  j  a  v a2s  . c  o m
@Test
@MobileTest(appPath = "sauce-storage:selendroid-test-app-0.15.0.apk", device = "android:4.3", deviceType = "Android Emulator", additionalCapabilities = {
        "appiumVersion:1.4.13" })
public void testWithNativeAndroidApp() throws Exception {
    RemoteWebDriver driver = Grid.driver();
    WebDriverWaitUtils.waitUntilElementIsVisible("io.selendroid.testapp:id/my_text_field");
    WebElement textField = driver.findElement(By.id("io.selendroid.testapp:id/my_text_field"));
    assertEquals("true", textField.getAttribute("enabled"));
    textField.sendKeys("Appium Android Native Test");
    assertEquals("Appium Android Native Test", textField.getText());

}

From source file:com.mycompany.myselion.sample.selion.SelendroidDemoTest.java

License:Apache License

/**
 * This test demonstrates how to use SeLion for running tests against ANDROID browser using selendroid.
 *///w  ww .  j a v a  2 s  .  co m
@Test
@MobileTest(appName = "android", device = "android:19")
public void testLaunch() throws Exception {
    RemoteWebDriver driver = Grid.driver();
    assertNotNull(driver);
    // 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();
    SeLionReporter.log("cheese!", true, true);
}

From source file:com.mycompany.myselion.sample.selion.SelendroidDemoTest.java

License:Apache License

/**
 * This test demonstrates how to use SeLion for running tests against ANDROID native app using selendroid.
 *///from  w  w  w .ja v a 2 s .  c o m
@Test
@MobileTest(appName = "io.selendroid.testapp:0.15.0", device = "android:19")
public void testNative() {
    RemoteWebDriver driver = Grid.driver();
    WebDriverWaitUtils.waitUntilElementIsVisible("//EditText[@id='my_text_field']");
    WebElement inputField = driver.findElement(By.xpath("//EditText[@id='my_text_field']"));
    assertEquals(inputField.getAttribute("enabled"), "true");
    inputField.sendKeys("Selendroid");
    assertEquals(inputField.getText(), "Selendroid");
}

From source file:com.mycompany.selenium.SeleniumExample.java

public static void main(String[] args) {

    System.setProperty("webdriver.chrome.driver", "/Applications/chromedriver");

    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.
    WebDriver driver = new ChromeDriver();

    //        System.setProperty("webdriver.chrome.driver", "/Users/CosticaTeodor/Downloads/drivers/chromedriver");

    // And now use this to visit Google
    driver.get("http://www.google.com");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("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();/*from ww w .  j a  v a  2  s .c o  m*/

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());

    // Google's search is rendered dynamically with JavaScript.
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.getTitle().toLowerCase().startsWith("cheese!");
        }
    });

    // Should see: "cheese! - Google Search"
    System.out.println("Page title is: " + driver.getTitle());

    //Close the browser
    driver.quit();
}