I have below piece of code, when executed it gets to correct page what I expect and clicks the needed links. But, the result is always shows Fail instead of Pass. After last step in the for loop, the focus jumps to catch loop and prints the resultDetails.setFlag(false)
and case fails. Please let me know where I'm wrong.
driver.findElement(By.linkText("ALL EQUIPMENT")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
List <WebElement> listings = driver.findElements(By.cssSelector("a[href*='/listing?listingid']"));
try {
for (int i=0; i < listings.size(); i++) {
WebElement requiredlisting = listings.get(i);
requiredlisting.click();
getvalue = driver.findElement(By.xpath("//div[7]/span")).getText();
System.out.println(getvalue);
driver.findElement(By.xpath("//div[3]/div[2]/input")).click();
Thread.sleep(10000);
driver.findElement(By.id("listingQuestion")).click();
Thread.sleep(10000);
driver.findElement(By.id("listingQuestion")).sendKeys("Where is the listing located");
Thread.sleep(10000);
driver.findElement(By.name("submitq")).click();
Thread.sleep(10000);
driver.findElement(By.xpath("//div/div[2]/div[3]/input")).click();
Thread.sleep(10000);
driver.findElement(By.id("uname")).click();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.linkText("Sign Out")).click();
driver.manage().deleteAllCookies();
driver.navigate().refresh();
driver.get(field);
driver.findElement(By.id("aurid")).sendKeys("mglaz@assetnation.com");
driver.findElement(By.id("apwd")).sendKeys("Equipment1$");
driver.findElement(By.xpath("//input[@value='Login']")).click();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.id("userAgreementBtn")).click();
Thread.sleep(10000);
System.out.println(getvalue);
driver.findElement(By.id("quicksearch")).sendKeys(getvalue);
Thread.sleep(10000);
driver.findElement(By.cssSelector("input.quicksearch_go")).click();
Thread.sleep(20000);
driver.findElement(By.linkText("Lot Q/A")).click();
Thread.sleep(10000);
driver.getPageSource().contains("my question");
driver.manage().deleteAllCookies();
driver.navigate().refresh();
resultDetails.setFlag(true);
}
}
catch (Exception e ) {
resultDetails.setFlag(false);
}