@@ -87,10 +87,7 @@ public static void main(String[] args) {
8787 setFilters ();
8888 boolean choice = false ;
8989 do {
90- //
9190 // Scroll thru the job Description
92-
93-
9491 List <WebElement > jobCards = driver
9592 .findElements (By .xpath ("/html/body/div[5]/div[3]/div[4]/div/div/main/div/div[1]/div/ul/li" ));
9693 int i = 1 ;
@@ -175,17 +172,18 @@ private static boolean hasWords(String[] jobTitleInCardWords, List<String> WORDS
175172 return mustHave ;
176173 }
177174
178- private static Boolean offerUserChoices () {
175+ private static boolean offerUserChoices () {
179176 String jobLocation = "United States" ;
180177 String jobTitle = "java developer" ;
181- System .out .println ("Choose from Options \n 1. Search new job Title \n 2.Change Job Location \n 3. Click next page & press 3 \n 4. exit\n " );
178+ System .out .println ("Choose from Options \n 1. Search new job Title \n 2. Change Job Location \n 3. Click next page & press 3 \n 4. exit \n " );
182179 // take input integer from user
183180 int choice = scanner .nextInt ();
184181 switch (choice ) {
185182 case 1 :
186- System .out .println ("Enter new job title" );
187- jobTitle = scanner .nextLine ();
188- getSearchResultsFor (jobTitle );
183+ Scanner sc2 = new Scanner (System .in ); //System.in is a standard input stream
184+ System .out .println ("Enter new job title\n " );
185+ jobTitle = sc2 .nextLine (); //reads string
186+ getSearchResultsFor (jobTitle , true );
189187 break ;
190188 case 2 :
191189 System .out .println ("Enter new job location" );
@@ -212,9 +210,9 @@ private static boolean elementExists(String xpath) {
212210 }
213211
214212 private static void chooseToApply (Scanner scanner ) {
215- System .out .println ("Do you want to apply for the job? (y/n) e to exit" );
213+ System .out .println ("Do you want to apply for the job? (y/n) e to exit\n " );
216214 String input = scanner .nextLine ();
217- if (input .equalsIgnoreCase ("e" ))
215+ if (input .trim (). equalsIgnoreCase ("e" ))
218216 {
219217 System .out .println ("Exiting the program" );
220218 closeBrowser ();
@@ -335,9 +333,19 @@ private static void clickWebElement(WebElement webElement) {
335333 }
336334
337335 private static void getSearchResultsFor (String jobTitle ) {
338- WebElement searchField = driver
339- .findElement (By .xpath ("/html/body/div[5]/header/div/div/div/div[2]/div[2]/div/div/input[1]" ));
340- randomSleep (SHORT_SLEEP );
336+
337+ WebElement searchField = driver .findElement (By .xpath ("/html/body/div[5]/header/div/div/div/div[2]/div[2]/div/div/input[1]" ));
338+ scrollToWebElement (searchField );
339+ sendKeysToWebElement (jobTitle , searchField );
340+ sendKeysToWebElement ("\n " , searchField );
341+ }
342+
343+ private static void getSearchResultsFor (String jobTitle , boolean newSearch ){
344+
345+ WebElement searchField = driver .findElement (By .xpath ("/html/body/div[5]/header/div/div/div/div[2]/div[1]/div/div/input[1]" ));
346+ scrollToWebElement (searchField );
347+ // Clear the search field
348+ searchField .clear ();
341349 sendKeysToWebElement (jobTitle , searchField );
342350 sendKeysToWebElement ("\n " , searchField );
343351 }
0 commit comments