-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPressKey.java
More file actions
46 lines (34 loc) · 1.25 KB
/
PressKey.java
File metadata and controls
46 lines (34 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package actions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
/**
* Created by jfarrier on 23/11/2016.
*/
public class PressKey {
//https://github.com/SeleniumHQ/selenium/wiki/Advanced-User-Interactions
public static void main(String[] args) throws InterruptedException {
//FirefoxDriver webdriver = new FirefoxDriver();
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver webdriver = new ChromeDriver();
webdriver.get("http://www.google.com");
//WebElement searchBar = webdriver.findElement(By.name("q"));
Actions builder = new Actions(webdriver);
Action type = builder.sendKeys("q").build();
/*
Select multiple
builder.keyDown(Keys.CONTROL)
.click(someElement)
.click(someOtherElement)
.keyUp(Keys.CONTROL);
*/
type.perform();
Thread.sleep(5000);
webdriver.get("http://www.google.com");
Thread.sleep(2000);
new Actions(webdriver).sendKeys("q").build().perform();
}
}