-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex2_FindThings.java
50 lines (36 loc) · 1.5 KB
/
ex2_FindThings.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
package examples;
import java.util.List;
import java.util.logging.Logger;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import utils.Config;
public class ex2_FindThings {
private static final Logger logger = Config.getLogger(ex2_FindThings.class);
public static void main(String[] args) {
new ex2_FindThings();
}
public ex2_FindThings() {
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.lookForStuff(drv);
drv.close();
}
public void lookForStuff(WebDriver drv) {
List<WebElement> elems = drv.findElements(By.xpath("//div"));
for (WebElement el : elems) {
logger.info("I found class: " + el.getAttribute("className") + " and text: " + el.getText());
}
WebElement elem = drv.findElement(By.cssSelector("h1"));
logger.info("h1 text is: " + elem.getText());
elem = drv.findElement(By.cssSelector(".aThing"));
logger.info(".aThing text is: " + elem.getText());
elem = drv.findElement(By.cssSelector("div.kittyBowl"));
logger.info("The kitty bowl picture url is: " + elem.getCssValue("background-image"));
elem = drv.findElement(By.id("nameInput"));
logger.info("The current kitty name is: " + elem.getAttribute("value"));
}
}