-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXPathSyntaxDemo.java
More file actions
24 lines (19 loc) · 841 Bytes
/
XPathSyntaxDemo.java
File metadata and controls
24 lines (19 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class XPathSyntaxDemo {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("http://localhost:8080/workspace/divs.html");
// WebElement p = driver.findElement(By.xpath("//p"));
WebElement id1 = driver.findElement(By.id("id1"));
// WebElement p = id1.findElement(By.xpath("/p")); // NoSuchElementException
// WebElement p = id1.findElement(By.xpath("//p")); // Hello
// WebElement p = id1.findElement(By.xpath("./p")); // World
WebElement p = id1.findElement(By.xpath(".//p")); // World
System.out.println(p.getText());
driver.quit();
}
}