0

I'm trying to write Selenium code for below HTML source code..

This field is the auto populated field for input selection

<input id="ctl00_ContentPlaceHolder1_txtBranch" class="textbox_service ui-autocomplete-input" name="ctl00$ContentPlaceHolder1$txtBranch" style="width: 200px;" onblur="return branch();" onchange="return CheckBranchName();" tabindex="6" autocomplete="off" type="text"/>

Any one can help me out to write the code?

Web element screen shot attached. Thanks in advance.

1

2 Answers 2

0

This is the best I could do with the information you provided. If you could show the HTML for what the autocomplete list looks like that would be great. You didn't specify any language so I'll assume it's Java.

WebElement field = driver.findElement(By.id("ctl00_ContentPlaceHolder1_txtBranch"));
field.click();
field.sendKeys(Keys.SPACE);

List<WebElement> items = driver.findElements(By.tagName("li");

for (int i=0; i<items.size();i++) {
WebElement elementYouWantToClick = items.get(i);
     String x = elementYouWantToClick.getText();
     if(x.contains("TextThatIsInYourElementYouWantToChoose")){
         elementYouWantToClick.click();
}

Best I could do for now with such limited information.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Thanks for code., When i am trying with bit change of your code drop down is displaying but item not able to select with code {driver.switchTo().frame(0); WebElement field = driver.findElement(By.id("ctl00_ContentPlaceHolder1_txtBranch")); field.click(); field.sendKeys(Keys.SPACE); Thread.sleep(3000); driver.switchTo().defaultContent(); driver.switchTo().frame(0); List<WebElement> items = field.findElements(By.tagName("li")); for (WebElement options1 : items) { if("MEHMDAVAD(DSH001)|1".equals(options1.getText())) { options1.click(); } }
What exception are you getting?
0

As per the HTML to click(select) the Auto Complete text, you can use the following line of code :

new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='textbox_service ui-autocomplete-input' and contains(@id,'_ContentPlaceHolder') and contains(@name,'txtBranch')]"))).click();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.