Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using OpenQA.Selenium;
  2. using OpenQA.Selenium.Firefox;
  3. using OpenQA.Selenium.Support.UI;
  4. using System;
  5. using System.Collections.Generic;
  6.  
  7. public class Program
  8. {
  9.     private static void Main(string[] args)
  10.     {
  11.         // The Firefox driver supports javascript
  12.         IWebDriver driver = new FirefoxDriver();
  13.  
  14.         // Go to the Google Suggest home page
  15.         driver.Navigate().GoToUrl("http://www.google.com/webhp?complete=1&hl=en");
  16.  
  17.         // Enter the query string "Cheese"
  18.         IWebElement query = driver.FindElement(By.Name("q"));
  19.         query.SendKeys("Cheese");
  20.  
  21.         // Wait for suggestion box
  22.         new WebDriverWait(driver, TimeSpan.FromSeconds(5))
  23.             .Until(ExpectedConditions.ElementIsVisible(By.ClassName("sbsb_b")));
  24.  
  25.         // And now list the suggestions
  26.         var allSuggestions = driver.FindElements(By.XPath("//*[contains(@id, 'sbse')]"));
  27.  
  28.         foreach (IWebElement suggestion in allSuggestions)
  29.         {
  30.             Console.WriteLine(suggestion.Text);
  31.         }
  32.  
  33.         driver.Quit();
  34.         Console.ReadKey();
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement