I am trying to locate all hyperlinks on a webpage of which the link text is also in the list, footerNames. I want to click the link, wait (will put a verification check in later), navigate back and then click the next link in the allLinksHrefs list (which should contain all the necessary webpage link elements). At the moment I am able to locate the first link, click it, navigate back but then the test fails. I am using Selenium WebDriver with C#. Thanks in advance.
public void TestFooterPageLinks()
{
List<IWebElement> allLinksHrefs = new List<IWebElement>();
List<String> allLinksText = new List<String>();
String currentUrl = Browser.Url;
List<String> footerNames = new List<String>();
footerNames.Add("About");
footerNames.Add("Press");
footerNames.Add("Safety");
footerNames.Add("Privacy");
footerNames.Add("Help");
footerNames.Add("Terms");
foreach (IWebElement link in Browser.FindElements(By.TagName("a")))
{
if (footerNames.Contains(link.Text))
{
if (allLinksHrefs.Contains(link)) {
continue;
}
else {
allLinksHrefs.Add(link);
Console.WriteLine(link);
}
}
}
foreach (IWebElement pageLink in allLinksHrefs)
{
Console.WriteLine(pageLink);
pageLink.Click();
Console.WriteLine(Browser.Title);
Browser.Wait(3);
Browser.Back();
}
}
}