Skip to content

Instantly share code, notes, and snippets.

@bharathmuddada
Created August 4, 2022 05:21
Show Gist options
  • Save bharathmuddada/a5705b57c27fb07d748ddbc73eedcdea to your computer and use it in GitHub Desktop.
Save bharathmuddada/a5705b57c27fb07d748ddbc73eedcdea to your computer and use it in GitHub Desktop.
Selenium C# program to fetch all the links from the google search results.
public class GoogleResults {
public static void Main(string[] args) {
new DriverManager().SetUpDriver(new ChromeConfig());
var driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://www.google.com/");
driver.Manage().Window.Maximize();
var search = driver.FindElement(By.Name("q"));
search.SendKeys("Selenium");
search.Submit();
var alllinks =
driver.FindElements(By.TagName("a"));
Console.WriteLine(alllinks.Count);
foreach (var link in alllinks) {
Console.WriteLine(link.GetAttribute("href"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment