-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex3_ChangeThings.java
51 lines (37 loc) · 1.44 KB
/
ex3_ChangeThings.java
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
47
48
49
50
51
package examples;
import java.util.logging.Logger;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import utils.Config;
public class ex3_ChangeThings {
private static final Logger logger = Config.getLogger(ex3_ChangeThings.class);
public static void main(String[] args) {
new ex3_ChangeThings();
}
public ex3_ChangeThings() {
Config cfg = new Config();
// Look at util.Config.createInstance for details
WebDriver drv = cfg.createInstance();
drv.navigate().to(cfg.get("site_url"));
logger.info("At the test site...");
this.changeStuff(drv);
drv.close();
}
public void changeStuff(WebDriver drv) {
WebElement elem = drv.findElement(By.id("nameInput"));
elem.clear();
elem.sendKeys("Garfield");
elem.sendKeys(Keys.ENTER);
logger.info("The new kitty name is: " + elem.getAttribute("value"));
elem = drv.findElement(By.xpath("//span[contains(@class, 'kittyName')]"));
logger.info("Somebody says: " + elem.getText());
WebElement button = drv.findElement(By.cssSelector(".kittyStart input"));
logger.info("Showing kitty");
button.click();
logger.info("Hiding kitty");
button.click();
// see WaitForThings, for an example on how to properly interact with a dropdown (SELECT tag)
}
}