I have create below script using List Element and For loop Conditions. Please review my scenario
Scenario:
Open Home Page > Click on drop down > Open the Drop down List.
Click on First option > Redirect to the specific screen and Verify the title.
Go back the same screen and Same scenario will be follow 4 times.
When I have execute my below script in Eclipse I have found the error. In my below coding first click is working but second click is not working in my drop-down.
@Test
public void toVerifyHelpLink() throws IOException, InterruptedException{
File src = new File("Object_Repo.properties");
FileInputStream fis = new FileInputStream(src);
pro = new Properties();
pro.load(fis);
Thread.sleep(2000);
WebElement linksdiv = driver.findElement(By.xpath(pro.getProperty("new_ul")));
List<WebElement> Links = linksdiv.findElements(By.tagName("a"));
System.out.println(Links.size());
for(int i=0; i<= Links.size()-1; i++)
{
driver.findElement(By.xpath(pro.getProperty("customerservice"))).click();
String subCategory = Links.get(i).getText();
System.out.println(subCategory);
Links.get(i).click();
if(!subCategory.equalsIgnoreCase("404")){
System.out.println("Title displaying as exepected");
}
driver.navigate().back();
linksdiv = driver.findElement(By.xpath(pro.getProperty("new_ul")));
Thread.sleep(2000);
}
}
This is the HTML structure is as below
<div class="customer-service effect">
<a href="">customer service</a>
<ul>
<li><a href="">Help</a></li>
<li><a href="">FAQs</a></li>
<li><a href="">Contact Us</a></li>
<li><a href="">Shipping and Returns</a></li>
</ul>
</div>