-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautomation.java
More file actions
68 lines (58 loc) · 3 KB
/
Copy pathautomation.java
File metadata and controls
68 lines (58 loc) · 3 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
65
66
67
68
package Automation.Automation;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.Date;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.io.FileHandler;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class App {
public static void main(String[] args) throws IOException {
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com/finance/?hl=en");
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0, 250)");
WebElement table = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='fAThCb']")));
List<WebElement> rows = table.findElements(By.xpath(".//div[contains(@class,'SxcTic')]"));
for (WebElement col : rows) {
System.out.println("Row: " + col.getText());
System.out.println("------------------");
}
for (WebElement row : rows) {
try {
WebElement priceElement = row.findElement(By.xpath(".//div[@class='YMlKec']"));
String amountText = priceElement.getText().replace("₹", "").replace(",", "").trim();
if (!amountText.isEmpty()) {
double price = Double.parseDouble(amountText);
if (price > 5000 && price < 25000) {
js.executeScript("arguments[0].style.border='3px solid red'", row);
WebElement tickerLink = row.findElement(By.xpath(".//div[@class='COaKTb']"));
}
}
} catch (Exception e) {
System.out.println("Skipping row due to error: " + e.getMessage());
}
}
WebElement detailAmount = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='YMlKec fxKbKc']")));
String detailAmountText = detailAmount.getText().replace("₹", "").replace(",", "").trim();
if (Double.parseDouble(detailAmountText) > 5000 && Double.parseDouble(detailAmountText) < 25000) {
System.out.println("Validated detail page amount successfully.");
}
File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File destFile = new File("screenshot_" + timeStamp + ".png");
FileHandler.copy(srcFile, destFile);
System.out.println("Screenshot saved at: " + destFile.getAbsolutePath());
}
}