| Line 66... |
Line 66... |
| 66 |
"--disable-popup-blocking",
|
66 |
"--disable-popup-blocking",
|
| 67 |
"--disable-notifications",
|
67 |
"--disable-notifications",
|
| 68 |
"--disable-extensions"
|
68 |
"--disable-extensions"
|
| 69 |
);
|
69 |
);
|
| 70 |
|
70 |
|
| - |
|
71 |
WebDriver driver = null;
|
| - |
|
72 |
|
| - |
|
73 |
try {
|
| 71 |
WebDriver driver = new ChromeDriver(options);
|
74 |
driver = new ChromeDriver(options);
|
| 72 |
driver.manage().timeouts().setScriptTimeout(6, TimeUnit.SECONDS);
|
75 |
driver.manage().timeouts().setScriptTimeout(6, TimeUnit.SECONDS);
|
| 73 |
driver.manage().window().setSize(new Dimension(1600, 900));
|
76 |
driver.manage().window().setSize(new Dimension(1600, 900));
|
| 74 |
driver.manage().window().maximize();
|
77 |
driver.manage().window().maximize();
|
| 75 |
// Deleting all the cookies
|
78 |
// Deleting all the cookies
|
| 76 |
driver.manage().deleteAllCookies();
|
79 |
driver.manage().deleteAllCookies();
|
| 77 |
// Specifiying pageLoadTimeout and Implicit wait
|
80 |
// Specifiying pageLoadTimeout and Implicit wait
|
| 78 |
driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
|
81 |
driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
|
| 79 |
driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
|
82 |
driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
|
| 80 |
|
83 |
|
| 81 |
int mainCount = 0;
|
84 |
int mainCount = 0;
|
| 82 |
List<String> remainingImeis = imeis;
|
85 |
List<String> remainingImeis = imeis;
|
| 83 |
WebDriverWait wait10Sec = new WebDriverWait(driver, 15);
|
86 |
WebDriverWait wait10Sec = new WebDriverWait(driver, 15);
|
| 84 |
WebDriverWait wait5Sec = new WebDriverWait(driver, 4);
|
87 |
WebDriverWait wait5Sec = new WebDriverWait(driver, 4);
|
| 85 |
WebElement slideButton;
|
88 |
WebElement slideButton;
|
| 86 |
Actions actionProvider = new Actions(driver);
|
89 |
Actions actionProvider = new Actions(driver);
|
| 87 |
do {
|
90 |
do {
|
| 88 |
driver.get("https://www.realme.com/in/support/phonecheck");
|
91 |
driver.get("https://www.realme.com/in/support/phonecheck");
|
| 89 |
/*try {
|
92 |
/*try {
|
| 90 |
driver.findElement(By.cssSelector(".cp-cookie-tip a.close")).click();
|
93 |
driver.findElement(By.cssSelector(".cp-cookie-tip a.close")).click();
|
| 91 |
} catch (Exception e) {
|
94 |
} catch (Exception e) {
|
| 92 |
try {
|
95 |
try {
|
| 93 |
System.out.println("Cookie not found");
|
96 |
System.out.println("Cookie not found");
|
| 94 |
} catch (Exception e1) {
|
97 |
} catch (Exception e1) {
|
| 95 |
}
|
98 |
}
|
| 96 |
}*/
|
99 |
}*/
|
| 97 |
|
100 |
|
| 98 |
for (int i = 0; i < remainingImeis.size(); i++) {
|
101 |
for (int i = 0; i < remainingImeis.size(); i++) {
|
| 99 |
String imei = remainingImeis.get(i);
|
102 |
String imei = remainingImeis.get(i);
|
| 100 |
try {
|
103 |
try {
|
| 101 |
System.out.println("Starting fresh with new IMEI " + imei);
|
104 |
System.out.println("Starting fresh with new IMEI " + imei);
|
| 102 |
if (driver.findElement(By.className("sn-input")).getAttribute("value").length() > 0) {
|
105 |
if (driver.findElement(By.className("sn-input")).getAttribute("value").length() > 0) {
|
| 103 |
//System.out.println("Darn.. leaving" + driver.findElement(By.className("el-input__inner")).getAttribute("value"));
|
106 |
//System.out.println("Darn.. leaving" + driver.findElement(By.className("el-input__inner")).getAttribute("value"));
|
| 104 |
driver.get("https://www.realme.com/in/support/phonecheck");
|
- |
|
| 105 |
break;
|
- |
|
| 106 |
}
|
- |
|
| 107 |
driver.findElement(By.className("sn-input")).sendKeys(imei);
|
- |
|
| 108 |
|
- |
|
| 109 |
//driver.findElement(By.className("el-button--primary")).click();
|
- |
|
| 110 |
driver.findElement(By.cssSelector("div.check-btn")).click();
|
- |
|
| 111 |
|
- |
|
| 112 |
// Perform click-and-hold action on the element
|
- |
|
| 113 |
int counter = 1;
|
- |
|
| 114 |
boolean captchaNotBroken = true;
|
- |
|
| 115 |
do {
|
- |
|
| 116 |
String fileName = "/tmp/oppo-simple-i-" + counter + " " + System.currentTimeMillis() + ".png";
|
- |
|
| 117 |
try {
|
- |
|
| 118 |
System.out.println("Starting Do");
|
- |
|
| 119 |
//Thread.sleep(5000);
|
- |
|
| 120 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.tagName("canvas")));
|
- |
|
| 121 |
|
- |
|
| 122 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_bg_')]")));
|
- |
|
| 123 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_wrapper_')]")));
|
- |
|
| 124 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]")));
|
- |
|
| 125 |
slideButton = driver.findElement(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]"));
|
- |
|
| 126 |
//System.out.println("Slide button - " + slideButton);
|
- |
|
| 127 |
System.out.println("Margin Left before- " + slideButton.getCssValue("margin-left"));
|
- |
|
| 128 |
actionProvider.moveToElement(slideButton).clickAndHold()
|
- |
|
| 129 |
.moveByOffset(1, 0)//.pause(2000)
|
- |
|
| 130 |
.perform();
|
- |
|
| 131 |
|
- |
|
| 132 |
//actionProvider.moveByOffset(-1,0).pause(2000).perform();
|
- |
|
| 133 |
System.out.println("Margin Left after - " + slideButton.getCssValue("margin-left"));
|
- |
|
| 134 |
//Thread.sleep(5000);
|
- |
|
| 135 |
} catch (Exception e) {
|
- |
|
| 136 |
System.out.println(e.getMessage());
|
- |
|
| 137 |
driver.get("https://www.realme.com/in/support/phonecheck");
|
107 |
driver.get("https://www.realme.com/in/support/phonecheck");
|
| 138 |
break;
|
108 |
break;
|
| 139 |
}
|
109 |
}
|
| - |
|
110 |
driver.findElement(By.className("sn-input")).sendKeys(imei);
|
| - |
|
111 |
|
| - |
|
112 |
//driver.findElement(By.className("el-button--primary")).click();
|
| - |
|
113 |
driver.findElement(By.cssSelector("div.check-btn")).click();
|
| - |
|
114 |
|
| - |
|
115 |
// Perform click-and-hold action on the element
|
| - |
|
116 |
int counter = 1;
|
| - |
|
117 |
boolean captchaNotBroken = true;
|
| - |
|
118 |
do {
|
| - |
|
119 |
String fileName = "/tmp/oppo-simple-i-" + counter + " " + System.currentTimeMillis() + ".png";
|
| - |
|
120 |
try {
|
| - |
|
121 |
System.out.println("Starting Do");
|
| - |
|
122 |
//Thread.sleep(5000);
|
| - |
|
123 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.tagName("canvas")));
|
| - |
|
124 |
|
| - |
|
125 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_bg_')]")));
|
| - |
|
126 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_wrapper_')]")));
|
| - |
|
127 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]")));
|
| - |
|
128 |
slideButton = driver.findElement(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]"));
|
| - |
|
129 |
//System.out.println("Slide button - " + slideButton);
|
| - |
|
130 |
System.out.println("Margin Left before- " + slideButton.getCssValue("margin-left"));
|
| - |
|
131 |
actionProvider.moveToElement(slideButton).clickAndHold()
|
| - |
|
132 |
.moveByOffset(1, 0)//.pause(2000)
|
| - |
|
133 |
.perform();
|
| - |
|
134 |
|
| - |
|
135 |
//actionProvider.moveByOffset(-1,0).pause(2000).perform();
|
| - |
|
136 |
System.out.println("Margin Left after - " + slideButton.getCssValue("margin-left"));
|
| - |
|
137 |
//Thread.sleep(5000);
|
| - |
|
138 |
} catch (Exception e) {
|
| - |
|
139 |
System.out.println(e.getMessage());
|
| - |
|
140 |
driver.get("https://www.realme.com/in/support/phonecheck");
|
| - |
|
141 |
break;
|
| - |
|
142 |
}
|
| 140 |
double[] circles = getMatCircles2(driver, fileName);
|
143 |
double[] circles = getMatCircles2(driver, fileName);
|
| 141 |
if (circles != null) {
|
144 |
if (circles != null) {
|
| 142 |
double firstCircleX = circles[0];
|
145 |
double firstCircleX = circles[0];
|
| 143 |
double secondCircleX = circles[1];
|
146 |
double secondCircleX = circles[1];
|
| 144 |
double distance = Math.abs(firstCircleX - secondCircleX);
|
147 |
double distance = Math.abs(firstCircleX - secondCircleX);
|
| 145 |
System.out.println("Distance is " + distance);
|
148 |
System.out.println("Distance is " + distance);
|
| 146 |
|
149 |
|
| 147 |
System.out.println("Starting Checkdistance method");
|
150 |
System.out.println("Starting Checkdistance method");
|
| 148 |
int moveByOffset = checkDistance(driver, wait10Sec, actionProvider, distance, slideButton);
|
151 |
int moveByOffset = checkDistance(driver, wait10Sec, actionProvider, distance, slideButton);
|
| 149 |
if (moveByOffset > 0) {
|
152 |
if (moveByOffset > 0) {
|
| 150 |
System.out.println("Margin Offset - " + slideButton.getCssValue("margin-left"));
|
153 |
System.out.println("Margin Offset - " + slideButton.getCssValue("margin-left"));
|
| 151 |
System.out.println("Ending Checkdistance method " + moveByOffset);
|
154 |
System.out.println("Ending Checkdistance method " + moveByOffset);
|
| 152 |
actionProvider.moveByOffset(moveByOffset, 0).release().perform();
|
155 |
actionProvider.moveByOffset(moveByOffset, 0).release().perform();
|
| 153 |
System.out.println("Move click performed");
|
156 |
System.out.println("Move click performed");
|
| 154 |
try {
|
- |
|
| 155 |
try {
|
157 |
try {
|
| - |
|
158 |
try {
|
| 156 |
wait5Sec.until(ExpectedConditions.visibilityOfElementLocated(By.className("dx_captcha_basic_bar-inform")));
|
159 |
wait5Sec.until(ExpectedConditions.visibilityOfElementLocated(By.className("dx_captcha_basic_bar-inform")));
|
| 157 |
System.out.println("Failed = " + counter);
|
160 |
System.out.println("Failed = " + counter);
|
| 158 |
} catch (Exception notFailedException) {
|
161 |
} catch (Exception notFailedException) {
|
| 159 |
System.out.println("Success at attempt " + counter);
|
162 |
System.out.println("Success at attempt " + counter);
|
| 160 |
//List<WebElement> warrantyDateElements = driver.findElements(By.className("warranty-service--result_info__dateValue"));
|
163 |
//List<WebElement> warrantyDateElements = driver.findElements(By.className("warranty-service--result_info__dateValue"));
|
| 161 |
//WebElement activationTimeElement = driver.findElement(By.xpath("//*[contains(text(), 'UTC+5.5') or contains(text(), 'Non-Activate')]"));
|
164 |
//WebElement activationTimeElement = driver.findElement(By.xpath("//*[contains(text(), 'UTC+5.5') or contains(text(), 'Non-Activate')]"));
|
| 162 |
WebElement warrantyStatus = driver.findElement(By.xpath(
|
165 |
WebElement warrantyStatus = driver.findElement(By.xpath(
|
| 163 |
"//label[text()='Estimated Warranty Expiration Date']/following-sibling::div/span | //h1[contains(@class, 'title')]"));
|
166 |
"//label[text()='Estimated Warranty Expiration Date']/following-sibling::div/span | //h1[contains(@class, 'title')]"));
|
| 164 |
|
- |
|
| 165 |
|
167 |
|
| 166 |
//TODO: IF not found activationElement
|
168 |
//TODO: IF not found activationElement
|
| 167 |
if (warrantyStatus != null) {
|
169 |
if (warrantyStatus != null) {
|
| 168 |
String activationDateString = warrantyStatus.getText().trim();
|
170 |
String activationDateString = warrantyStatus.getText().trim();
|
| 169 |
System.out.println("Date -- " + activationDateString);
|
- |
|
| 170 |
try {
|
- |
|
| 171 |
dateMap.put(imei, LocalDate.parse(activationDateString.split(" ")[0], DateTimeFormatter.ofPattern("yyyy.MM.dd")).minusYears(1));
|
- |
|
| 172 |
System.out.println("Date -- " + activationDateString);
|
171 |
System.out.println("Date -- " + activationDateString);
|
| - |
|
172 |
try {
|
| - |
|
173 |
dateMap.put(imei, LocalDate.parse(activationDateString.split(" ")[0], DateTimeFormatter.ofPattern("yyyy.MM.dd")).minusYears(1));
|
| - |
|
174 |
System.out.println("Date -- " + activationDateString);
|
| 173 |
} catch (Exception e) {
|
175 |
} catch (Exception e) {
|
| - |
|
176 |
dateMap.put(imei, null);
|
| - |
|
177 |
}
|
| - |
|
178 |
} else {
|
| - |
|
179 |
System.out.println("Could not capture date");
|
| 174 |
dateMap.put(imei, null);
|
180 |
dateMap.put(imei, null);
|
| 175 |
}
|
181 |
}
|
| 176 |
} else {
|
- |
|
| 177 |
System.out.println("Could not capture date");
|
182 |
if (dateMap.size() == imeis.size()) {
|
| 178 |
dateMap.put(imei, null);
|
183 |
return dateMap;
|
| 179 |
}
|
184 |
}
|
| 180 |
if(dateMap.size()==imeis.size()) {
|
185 |
WebElement checkAgainButton = driver.findElement(By.className("recheck-btn"));
|
| 181 |
driver.close();
|
186 |
captchaNotBroken = false;
|
| 182 |
driver.quit();
|
187 |
checkAgainButton.click();
|
| 183 |
return dateMap;
|
188 |
break;
|
| 184 |
}
|
189 |
}
|
| 185 |
WebElement checkAgainButton = driver.findElement(By.className("recheck-btn"));
|
- |
|
| 186 |
captchaNotBroken = false;
|
190 |
} catch (Throwable e) {
|
| 187 |
checkAgainButton.click();
|
191 |
System.out.println("Failed = " + counter + " ----------" + e.getMessage());
|
| 188 |
break;
|
- |
|
| 189 |
}
|
192 |
}
|
| 190 |
} catch (Throwable e) {
|
- |
|
| 191 |
System.out.println("Failed = " + counter + " ----------" + e.getMessage());
|
- |
|
| 192 |
}
|
193 |
}
|
| 193 |
}
|
194 |
}
|
| 194 |
}
|
- |
|
| 195 |
System.out.println("After circles conditions");
|
195 |
System.out.println("After circles conditions");
|
| 196 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_wrapper_')]")));
|
196 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_wrapper_')]")));
|
| 197 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]")));
|
197 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]")));
|
| 198 |
slideButton = driver.findElement(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]"));
|
198 |
slideButton = driver.findElement(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]"));
|
| 199 |
actionProvider.moveToElement(slideButton).doubleClick().perform();
|
199 |
actionProvider.moveToElement(slideButton).doubleClick().perform();
|
| 200 |
System.out.println("Ending Do" + counter++);
|
200 |
System.out.println("Ending Do" + counter++);
|
| 201 |
|
201 |
|
| 202 |
} while (captchaNotBroken && counter <= 20);
|
202 |
} while (captchaNotBroken && counter <= 20);
|
| 203 |
System.out.println("Counter reached upto 20");
|
203 |
System.out.println("Counter reached upto 20");
|
| - |
|
204 |
} catch (Exception e) {
|
| - |
|
205 |
System.out.println("Caught unknown - for imei " + imei);
|
| - |
|
206 |
e.printStackTrace();
|
| - |
|
207 |
}
|
| - |
|
208 |
driver.get("https://www.realme.com/in/support/phonecheck");
|
| - |
|
209 |
}
|
| - |
|
210 |
mainCount++;
|
| - |
|
211 |
remainingImeis = imeis.stream().filter(x -> !dateMap.containsKey(x)).collect(Collectors.toList());
|
| - |
|
212 |
} while (mainCount < 5);
|
| - |
|
213 |
} finally {
|
| - |
|
214 |
if (driver != null) {
|
| - |
|
215 |
try {
|
| - |
|
216 |
driver.quit(); // ✅ Always shuts everything down
|
| 204 |
} catch (Exception e) {
|
217 |
} catch (Exception e) {
|
| 205 |
System.out.println("Caught unknown - for imei " + imei);
|
218 |
System.out.println("Error closing driver: " + e.getMessage());
|
| 206 |
e.printStackTrace();
|
- |
|
| 207 |
}
|
219 |
}
|
| 208 |
driver.get("https://www.realme.com/in/support/phonecheck");
|
- |
|
| 209 |
}
|
220 |
}
|
| 210 |
mainCount++;
|
- |
|
| 211 |
remainingImeis = imeis.stream().filter(x -> !dateMap.containsKey(x)).collect(Collectors.toList());
|
- |
|
| 212 |
} while (mainCount < 5);
|
- |
|
| 213 |
driver.close();
|
- |
|
| 214 |
driver.quit();
|
221 |
}
|
| - |
|
222 |
|
| 215 |
return dateMap;
|
223 |
return dateMap;
|
| 216 |
}
|
224 |
}
|
| 217 |
|
225 |
|
| - |
|
226 |
|
| 218 |
private int checkDistance(WebDriver driver, WebDriverWait wait3Sec, Actions actionProvider, double distance, WebElement slideButton) throws Exception {
|
227 |
private int checkDistance(WebDriver driver, WebDriverWait wait3Sec, Actions actionProvider, double distance, WebElement slideButton) throws Exception {
|
| 219 |
|
228 |
|
| 220 |
//actionProvider.moveToElement(slideButton).clickAndHold().moveByOffset(1, 0).perform();
|
229 |
//actionProvider.moveToElement(slideButton).clickAndHold().moveByOffset(1, 0).perform();
|
| 221 |
actionProvider.moveByOffset(15, 0).perform();
|
230 |
actionProvider.moveByOffset(15, 0).perform();
|
| 222 |
String fileName2 = "/tmp/" + Thread.currentThread().getName() + "-moved.png";
|
231 |
String fileName2 = "/tmp/" + Thread.currentThread().getName() + "-moved.png";
|