title: how to google search using dynamic xpath?
body: <p>I am trying to automate the Google Search for "Java" and when it provides a list, I want to select "java interview questions".
  I tried using the below xpath, but the script is failing.</p>
  
  <pre><code>List&lt;WebElement&gt; list = driver.findElements(By.xpath("//ul[@role ='listbox']//li/descendent::div[@class='sbl1']"));
  </code></pre>
  
  <p>Below is my code for the same - </p>
  
  <pre><code>public class GoogleSearchTest {
  
      public static void main(String[] args) {
  
          System.setProperty("webdriver.chrome.driver" , "C:/Users/User/Desktop/Selenium Drivers/chromedriver.exe");
          WebDriver driver = new ChromeDriver();
          driver.get("http://www.google.com");
          driver.manage().window().maximize();
          driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
  
          driver.findElement(By.name("q")).sendKeys("Java");
  
          List&lt;WebElement&gt; list = driver.findElements(By.xpath("//ul[@role ='listbox']//li/descendent::div[@class='sbl1']"));
          System.out.println("Total no of suggestions in search box::" +list.size());
  
          for(int i=0; i&lt;list.size();i++) {
              System.out.println(list.get(i));
  
              if(list.get(i).getText().contains("Java Tutorial")) {
                  list.get(i).click();
                  break;
              }
          }
      }
  
  }
  </code></pre>