-
Notifications
You must be signed in to change notification settings - Fork 0
/
JavascriptExample.java
36 lines (26 loc) · 1.21 KB
/
JavascriptExample.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
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
public class JavascriptExample {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "/Users/tanvi/Documents/automation_testing/chromedriver");
WebDriver chromeDriver = new ChromeDriver();
chromeDriver.get("https://rahulshettyacademy.com/AutomationPractice/");
//JavascriptExecutor js = (JavascriptExecutor)chromeDriver;
//js.executeScript("window.scroll(0,500)");
//Thread.sleep(2000);
//js.executeScript("document.querySelector('.tableFixHead').scrollTop=5000");
List<WebElement> valuesColumn = chromeDriver.findElements(By.cssSelector(".tableFixHead td:nth-child(4)"));
int total=0;
for (WebElement value : valuesColumn) {
total+=Integer.parseInt(value.getText());
}
System.out.println(total);
int expected = Integer.parseInt((chromeDriver.findElement(By.cssSelector(".totalAmount")).getText().split(":")[1].trim()));
Assert.assertEquals(total, expected);
}
}