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