How to send keyboard keys combination in selenium webdriver


package selenium_examples;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Example {
simulating keyboard keys webdriver
 public static void main(String[] args)
     {

  WebDriver driver = new FirefoxDriver();
  driver.get("http://www.google.com");
  driver.findElement(By.name("q")).sendKeys(Keys.NUMPAD1,Keys.ADD,Keys.NUMPAD2, Keys.ADD, Keys.NUMPAD3, Keys.EQUALS,Keys.ENTER);
 
  }
 
  }
   
Script2:-
Script in Selenium Webdriver to Simulate CTRL + A,to select all content in Webpage.
package selenium_examples;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Test {
 public static void main(String[] args) {
 
 
  WebDriver driver = new FirefoxDriver();
     driver.get("http://google.com");
     driver.findElement(By.xpath("//body")).sendKeys(Keys.chord(Keys.CONTROL, "a"));
 
   
  }
}

 

No comments:

Related Posts Plugin for WordPress, Blogger...

Fun and Knowledge