Dana Dana - 28 days ago 17
Java Question

Need to check 500 Titles in 5 pages (Each page contains 100 Titles) and each title has to click and check particular heading on that page title

Checking 500 titles in 5 pages and check heading on each title :
Let me know the corrections please

WebElement value = driver.findElement(By.id("numberOfResults"));
Select selectElement = new Select(value);
selectElement.selectByValue("100");

List<WebElement> PostTitles = driver.findElements(By.className("hlFld-Title"));

for (WebElement eachTitle : PostTitles)
{
System.out.println(eachTitle.getText());
// String Titles = eachTitle.getText();

int Size = PostTitles.size();
for (int i = 0; i < eachTitle; i++)
{
driver.findElement(By.linkText(eachTitle.getText())).click();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.linkText("HEADING")).click();
System.out.println(driver.getCurrentUrl());
driver.navigate().back();
driver.navigate().back();
}
}

Answer

Implemented this logic , Successfully executed, with No Errors

List<WebElement> linkElements=driver.findElements(By.xpath("************"));
String[] linkTitles = new String[linkElements.size()];
int i = 0;
//extract the link texts of each link element
for (WebElement e : linkElements) 
{
    linkTitles[i] = e.getText();
    i++;
}
//Test each link
for (String t : linkTitles) 
{
    // Titles Click 
    driver.findElement(By.linkText(t)).click();
    System.out.println("\n"+ driver.getTitle());
    Thread.sleep(7000);
   driver.findElement(By.linkText("Heading Notes")).click();
   System.out.println(driver.findElement(By.xpath("*****")).getText());
   System.out.println(driver.getCurrentUrl());
   driver.navigate().back();
   driver.navigate().back();
   Thread.sleep(7000);
}