Skip to content

Commit 5f2fc9e

Browse files
committed
Feature: Now Supports jobs with just a submit button without reviewing
1 parent 1465449 commit 5f2fc9e

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

src/main/java/org/example/Main.java

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package org.example;
22

3-
import org.openqa.selenium.By;
4-
import org.openqa.selenium.JavascriptExecutor;
3+
import org.openqa.selenium.*;
54
import org.openqa.selenium.NoSuchElementException;
6-
import org.openqa.selenium.WebDriver;
7-
import org.openqa.selenium.WebElement;
85
import org.openqa.selenium.chrome.ChromeDriver;
96
import org.slf4j.Logger;
107
import org.slf4j.LoggerFactory;
@@ -97,6 +94,7 @@ public static void main(String[] args) {
9794
// /html/body/div[5]/div[3]/div[4]/div/div/main/div/div[1]/div/ul/li[1]
9895
WebElement view = driver.findElement(
9996
By.xpath("/html/body/div[5]/div[3]/div[4]/div/div/main/div/div[1]/div/ul/li[" + i + "]"));
97+
10098
scrollToWebElement(view);
10199
// get the aria label in this element as job Title In Card,
102100
// if it contains any of the MUST_HAVE, then click on the card
@@ -109,6 +107,7 @@ public static void main(String[] args) {
109107

110108
// Print the content
111109

110+
logger.info("Clicking job card with xpath: " + "/html/body/div[5]/div[3]/div[4]/div/div/main/div/div[1]/div/ul/li[" + i + "]");
112111
i++;
113112

114113
// process job Title in Card by removing special characters with space and split the job Title into words
@@ -217,14 +216,13 @@ private static void applyForThisJob() {
217216

218217
// xpath for next button:
219218
// /html/body/div[3]/div/div/div[2]/div/div[2]/form/footer/div[2]/button
220-
try{
221-
WebElement formFooter = driver.findElement(By.xpath(
222-
"/html/body/div[3]/div/div/div[2]/div/div[2]/form/footer"));
223-
WebElement nextButton = formFooter.findElement(By.cssSelector(".artdeco-button--primary.ember-view"));
219+
try {
220+
WebElement formFooter = driver.findElement(By.xpath(
221+
"/html/body/div[3]/div/div/div[2]/div/div[2]/form/footer"));
222+
WebElement nextButton = formFooter.findElement(By.cssSelector(".artdeco-button--primary.ember-view"));
224223
//find the button in the formFooter that has the CSS class artdeco-button--primary ember-view
225224
while (formFooter != null && nextButton != null) {
226-
js.executeScript("arguments[0].scrollIntoView();", nextButton);
227-
//Log found next button
225+
scrollToWebElement(nextButton, false);
228226
logger.info("Found next button");
229227
//get next button aria lable
230228
String nextButtonAriaLabel = nextButton.getAttribute("aria-label");
@@ -237,29 +235,45 @@ private static void applyForThisJob() {
237235
nextButton = formFooter.findElement(By.cssSelector(".artdeco-button--primary.ember-view"));
238236
}
239237

240-
// submit button xpath:
241-
// /html/body/div[3]/div/div/div[2]/div/div[2]/div/footer/div[3]/button[2]
242-
/// html/body/div[3]/div/div/div[2]/div/div[2]/div/footer/div[2]/button[2]
238+
// submit button xpath:
239+
// /html/body/div[3]/div/div/div[2]/div/div[2]/div/footer/div[3]/button[2]
240+
/// html/body/div[3]/div/div/div[2]/div/div[2]/div/footer/div[2]/button[2]
241+
// /html/body/div[3]/div/div/div[2]/div/div[2]/div/footer/div[3]/button[2]
243242
// scroll to the submit button
243+
244+
245+
}
246+
catch (Exception e) {
247+
logger.info(e.getMessage());
248+
}
249+
try {
244250
WebElement submitButton = driver.findElement(By.xpath(
245251
"/html/body/div[3]/div/div/div[2]/div/div[2]/div/footer")).findElement(By.cssSelector(".artdeco-button--primary.ember-view"));
246-
scrollToWebElement(submitButton);
252+
scrollToWebElement(submitButton, false);
253+
submitButton.click();
254+
randomSleep(LONG_SLEEP);
255+
} catch (NoSuchElementException e) {
256+
WebElement submitButton = driver.findElement(By.xpath(
257+
"/html/body/div[3]/div/div/div[2]/div/div/form/footer/")).findElement(By.cssSelector(".artdeco-button--primary.ember-view"));
258+
scrollToWebElement(submitButton, false);
247259
submitButton.click();
248260
randomSleep(LONG_SLEEP);
249-
250-
WebElement closeButton = driver.findElement(By.xpath("/html/body/div[3]/div/div/button"));
251-
closeButton.click();
252-
253-
} catch(NoSuchElementException e){
254-
logger.info("Issue sumbitting application \n Sumbit manually and press enter to continue");
255-
scanner.nextLine();
256261
}
257262
catch (Exception e) {
258263
logger.info(e.getMessage());
259264
}
260265

266+
WebElement closeButton = driver.findElement(By.xpath("/html/body/div[3]/div/div/button"));
267+
closeButton.click();
261268
// Sleep for 5 secondsn
262269

270+
// single click submit jobs
271+
// <button aria-label="Submit application" id="ember1409" class="artdeco-button artdeco-button--2 artdeco-button--primary ember-view" type="button"><!---->
272+
//<span class="artdeco-button__text">
273+
// Submit application
274+
// </span></button>
275+
// xpath: /html/body/div[3]/div/div/div[2]/div/div/form/footer/div[3]/button
276+
263277
}
264278

265279
private static void setFilters() {
@@ -309,15 +323,21 @@ private static void scrollToWebElement(WebElement contractExperienceLevel) {
309323
randomSleep(SHORT_SLEEP);
310324
}
311325

326+
private static void scrollToWebElement(WebElement contractExperienceLevel, boolean sleep) {
327+
js.executeScript("arguments[0].scrollIntoView();", contractExperienceLevel);
328+
if (sleep)
329+
randomSleep(SHORT_SLEEP);
330+
}
312331
private static void clickWebElement(WebElement webElement) {
313332
js.executeScript("arguments[0].click();", webElement);
314333
randomSleep(SHORT_SLEEP);
315334
}
316335

317336
private static void getSearchResultsFor(String jobTitle) {
318-
337+
///html/body/div[4]/header/div/div/div/div[2]/div[2]/div/div[2]/input[1]
319338
WebElement searchField = driver.findElement(By.xpath("/html/body/div[5]/header/div/div/div/div[2]/div[2]/div/div/input[1]"));
320-
scrollToWebElement(searchField);
339+
js.executeScript("arguments[0].scrollIntoView();", searchField);
340+
// scrollToWebElement(searchField);
321341
sendKeysToWebElement(jobTitle, searchField);
322342
sendKeysToWebElement("\n", searchField);
323343
}

0 commit comments

Comments
 (0)