title: How to click on search text results in selenium WebDriver
body: <p>How to click on a specific text of search text box results in selenium WebDriver. In my case search text box is &quot;School&quot;.</p>
  <p>I'm sending keys &quot;RGSchool1&quot; in the text box &quot;School&quot; and then I want to click on &quot;RGScool&quot; when it shows up as results under the text box.</p>
  <p>I tried all below approached by it's throwing &quot;org.openqa.selenium.NoSuchElementException&quot;</p>
  <ol>
  <li>Enter text and tab out</li>
  <li>Enter text and send enter key</li>
  <li>Absolute path  -  /html<a href="https://i.stack.imgur.com/qIvqO.png" rel="nofollow noreferrer">1</a>/body<a href="https://i.stack.imgur.com/qIvqO.png" rel="nofollow noreferrer">1</a>/div[7]/ul<a href="https://i.stack.imgur.com/qIvqO.png" rel="nofollow noreferrer">1</a>/li<a href="https://i.stack.imgur.com/qIvqO.png" rel="nofollow noreferrer">1</a>/div<a href="https://i.stack.imgur.com/qIvqO.png" rel="nofollow noreferrer">1</a>/span<a href="https://i.stack.imgur.com/qIvqO.png" rel="nofollow noreferrer">1</a></li>
  <li>Relative path  -  //span[@class='select2-match']</li>
  </ol>
  <p>HTML body:</p>
  <pre><code>&lt;div class=&quot;select2-result-label&quot; style=&quot;&quot; xpath=&quot;1&quot;&gt;
  &lt;span class=&quot;select2-match&quot;&gt;RGSchoo&lt;/span&gt;
  l1 [rgschool1]&lt;/div&gt;
  </code></pre>
  <p>Code:
  //Finding elements</p>
  <pre><code>@FindBy(id = &quot;s2id_User_OrgId&quot;)
  public WebElement clickJurisdiction;
  
  @FindBy(xpath = &quot;/html[1]/body[1]/div[6]/div[1]/input[1]&quot;)
  public WebElement keyInJurisdiction;
  
  @FindBy(xpath = &quot;//div[@id='s2id_User_OrgUnitId']//a[@class='select2-        choice']&quot;)
  public WebElement clickSchool;
  
  @FindBy(xpath = &quot;/html[1]/body[1]/div[7]/div[1]/input[1]&quot;)
  public WebElement keyInSchool;
  
  @FindBy(xpath = &quot;/html[1]/body[1]/div[7]/ul[1]/li[1]/div[1]&quot;)
  public WebElement schoolSearchResult2;
  </code></pre>
  <p>Call method:</p>
  <pre><code>public void enterNewUserData() {
  
      SeleniumTestHelper.enterText(firstName, Config.getProperty(&quot;FirstName&quot;));
      SeleniumTestHelper.enterText(middleName, Config.getProperty(&quot;MiddleName&quot;));
      SeleniumTestHelper.enterText(lastName, Config.getProperty(&quot;LastName&quot;));
      SeleniumTestHelper.enterText(preferredName, Config.getProperty(&quot;PreferredName&quot;));
      
      SeleniumTestHelper.clickOnButton(clickJurisdiction);
      SeleniumTestHelper.enterText(keyInJurisdiction, Config.getProperty(&quot;Jurisdiction&quot;));
      SeleniumTestHelper.enter(keyInJurisdiction);
  
      SeleniumTestHelper.clickOnButton(clickSchool);
      SeleniumTestHelper.enterText(keyInSchool, Config.getProperty(&quot;School&quot;));
      SeleniumTestHelper.clickOnButton(schoolSearchResult2); // It fails here
  </code></pre>
  <p>Please help me to find a solution. I'm new to this kind of scenario.</p>
  <p>Please see the below-attached screenshot.</p>
  <p>Screenshot before entering data:</p>
  <p><img src="https://i.stack.imgur.com/qIvqO.png" alt="Screenshot before entering data" /></p>
  <p><a href="https://i.stack.imgur.com/rfpwL.png" rel="nofollow noreferrer">Screenshot after entering data</a></p>