-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsingElementsTest.java
More file actions
64 lines (54 loc) · 1.9 KB
/
UsingElementsTest.java
File metadata and controls
64 lines (54 loc) · 1.9 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.List;
public class UsingElementsTest {
private static WebDriver driver;
@BeforeClass
public static void runOnceBeforeClass() {
System.setProperty("webdriver.chrome.driver" , "C:\\Users\\dgotl\\Downloads\\chromedriver_win32\\ChromeDriver.exe");
driver = new ChromeDriver();
driver.get("https://translate.google.com");
}
@Test
public void test01_clickAnElement() {
driver.findElement(By.id("source")).click();
}
@Test
public void test02_submitForm() {
driver.findElement(By.id("source")).submit();
}
@Test
public void test03_sendKeys() {
driver.findElement(By.id("source")).sendKeys("hello");
}
@Test
public void test04_clearTextArea() {
driver.findElement(By.id("source")).clear();
}
// todo @Test - will not work now...
public void test05_clickAnElementFromAListWithAKnownIndex() {
List<WebElement> buttonsList = driver.findElements(By.id("Button"));
buttonsList.get(3).click();
}
//todo @Test - will not work now...
public void test06_iteratingAListOfElements(){
// Create a list of all elements with the ID=Button
List<WebElement> buttonsList = driver.findElements(By.id("Button"));
// Iterating through the list
for (WebElement currentButton : buttonsList) {
// Finding a specific element with a specific text and clicking it
if (currentButton.getText().equals("button1")) {
currentButton.click();
}
}
}
@AfterClass
public static void tearDown(){
driver.quit();
}
}