Question

Before posting this, I've thoroughly researched all possible syntax available for this and got no avail.

The closest I had was using this code where the dropdown actually appeared but didn't select my desired option:

new WebDriverWait(driver,10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("html/body/form/table/tbody/tr[4]/td/div/fieldset/table/tbody/tr/td[1]/table/tbody/tr[3]/td[2]/select")));

driver.findElement(By.xpath("html/body/form/table/tbody/tr[4]/td/div/fieldset/table/tbody/tr/td[1]/table/tbody/tr[3]/td[2]/select")).sendKeys("Local Move"); 

new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("html/body/form/table/tbody/tr[4]/td/div/fieldset/table/tbody/tr/td[1]/table/tbody/tr[3]/td[2]/select"))).click();

I spent a significant amount of time today figuring this one out but I really failed on this one big time.

Was it helpful?

Solution

WebElement dropDownListBox = driver.findElement(By.xpath("html/body/form/table/tbody/tr[4]/td/div/fieldset/table/tbody/tr/td[1]/table/tbody/tr[3]/td[2]/select")); 

Select clickThis = new Select(dropDownListBox);
Thread.sleep(5000L);
clickThis.selectByValue("1078");

It seems I needed Thread.sleep to let the system display the options completely before selenium can find the option I want for it to choose from.

Thanks guys!

OTHER TIPS

To select a value from drop down. You need to use Select class from web driver.

driver.findElement(By.xpath("html/body/form/table/tbody/tr[4]/td/div/fieldset/table/tbody/tr/td[1]/table/tbody/tr[3]/td[2]/select")).sendKeys("Local Move");

Instead of the above line use this

WebElement ele = driver.findElement(By.xpath("html/body/form/table/tbody/tr[4]/td/div/fieldset/table/tbody/tr/td[1]/table/tbody/tr[3]/td[2]/select"));
Select dropdown = new Select(ele);
dropdown.selectByVisibleText("Local Move");
// Can select the dropdown using `index` and `value`
dropdown.selectByValue("Local Move");
dropdown.selectByIndex("1234");

To select a value from dropdown you should find the dropdown element by id then by value in the dropdown.

Try this:

new Select(driver.findElement(By.id("Dropdownid"))).selectByVisibleText("Text name");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top