-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindElemntByXPath.java
More file actions
45 lines (33 loc) · 1.04 KB
/
FindElemntByXPath.java
File metadata and controls
45 lines (33 loc) · 1.04 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
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class FindElemntByXPath {
private WebDriver driver;
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver");
driver = new ChromeDriver();
}
@After
public void tearDown() {
driver.quit();
}
@Test
public void testRow () {
driver.get("http://localhost:8080/workspace/xpath.html");
// find product and price based its quality of '200'
WebElement product = driver.findElement(By.xpath(
"//table[@id='tbl']//td[text()='200']/preceding-sibling::td[2]"
));
WebElement price = driver.findElement(By.xpath(
"//table[@id='tbl']//td[text()='200']/preceding-sibling::td[1]"
));
assertEquals("DVDs", product.getText());
assertEquals("$45", price.getText());
}
}