1
Driver.findElement(By.xpath("//*[@id='client']")).sendKeys("Ho");
Driver.manage().timeouts().implicitlyWait(1,TimeUnit.MINUTES);

WebElement dropdown = (new WebDriverWait(Driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='client']")));

Driver.findElement(By.xpath("//*[@id='collapseClientInfo']/div/form/div[3]/div[2]/ul/li[1]/a")).sendKeys(Keys.ENTER);

Could you please help me to select auto populate value from drop down list:

  1. We've Client textbox which is an auto-populate box.
  2. When I enter "ho" text in the client field, it shows me the drop down which has values related to my entered text i.e. ho, then I have to select those values which are available under list.
  3. In above code I've tried with Press Enter but unable to select the value.

Could you please check the above code and help me out for the same?

10
  • Could you share the website URL or relevant HTML??.... Commented Feb 14, 2017 at 12:02
  • package ChromeBrowser; public static void main(String[] args) { Driver.findElement(By.xpath("//*[@id='client']")).sendKeys("Ho"); Driver.manage().timeouts().implicitlyWait(1,TimeUnit.MINUTES); WebElement dropdown = (new WebDriverWait(Driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='client']"))); Driver.findElement(By.xpath("//*[@id='collapseClientInfo']/div/form/div[3]/div[2]/ul/li[1]/a")).sendKeys(Keys.ENTER); }} Please check above code. Commented Feb 14, 2017 at 12:08
  • But where we can check your code.?? Commented Feb 14, 2017 at 12:09
  • Sourabh, Sorry this is my company website i cant share the credential, I can share the specific information for the same? Commented Feb 14, 2017 at 12:12
  • 1
    URL - bioceptbetaweb.azurewebsites.net Username - [email protected] PWD- Ajay@123 After login, please click on 'Place a new order' Then on Client field we've to select value from autopopulate popup. Please check Commented Feb 14, 2017 at 12:18

3 Answers 3

2

You should try as below :-

WebDriverWait wait = new WebDriverWait(Driver, 60);

//wait until loader invisible
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("loaderDiv")));

//this sleep is required because after invisibility of loader focus goes to first input which is Requisition Number
//If you are filling form from first input no need to for this sleep
//if you want to input directly to client field need to sleep to avoid focus first  
Thread.sleep(3000);

//Now find the client input and set value
WebElement client = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("client")));
client.sendKeys("Ho");

//Now find all the showing option   
List<WebElement> dropdownOptions = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("ul.dropdown-menu a")));

//Now select the first option
dropdownOptions.get(0).click();
Sign up to request clarification or add additional context in comments.

8 Comments

Thank you for the code. It works fine but now I've tried the same thing in next field and unable to find the element. In the above code, you've selected "CSS Selector" that you have selected from the code, right?
@ajaykumar Yes, May be there are some different selector would work, try to identify the locator..:)
I've tried with ID and CSS path but its not working.
@ajaykumar then you can ask another question regarding this.. Thanks..:)
Thank you, so the scenario is: 1. Without selecting client we cannot select facility as its disabled. 2. We've selected client value from drop down. 3. Now I've written a script for a new tab. 4. After that, I've to find facility field through ID but it shows element is not found, then could you please help me for the same?
|
1

Below approach might be helpful:

// Enter text in auto complete text box
driver.findElement(By.xpath("//*[@id='client']")).sendKeys("Ho");

// Wait for options to display
Thread.sleep(5000);

// Option to select
String optionToSelect = "Honda";

Boolean isOptionSelected = Boolean.FALSE;

// Get the options displayed
List<WebElement> options = driver.findElements(By
        .cssSelector("ul.dropdown-menu a"));

// Select option
for (WebElement webElement : options) {
    if (webElement.getText().equalsIgnoreCase(optionToSelect)) {
        webElement.click();
        isOptionSelected = Boolean.TRUE;
    }
}

if (isOptionSelected) {
    // Option is selected
} else {
    // Expected option is not displayed. Fail the script
}

1 Comment

I guess this is for good option if i want to select any particular value
0

Try this:

Select drpCountry = new Select(driver.findElement(By.id("searchOptions")));
drpCountry.selectByVisibleText("By author");

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.