Select a value from input combo box using Selenium using xpath for a reachjs control
Please follow the below step to select your desired element
- Click on the down arrow of dropdown
- Select the desired option
Here is the code for same :
driver.findElement(By.xpath("//h3[contains(text(),'States')]/..//span[@class='Select-arrow']")).click();driver.findElement(By.id("react-select-2--option-1")).click();
Updated
Use the below method to select the value dynamically based on text :
public void selectCombo(String valueText){ driver.findElement(By.xpath("//h3[contains(text(),'States')]/..//span[@class='Select-arrow']")).click(); WebElement dropdownValue = driver.findElement(By.xpath("//div[contains(text(),'"+valueText+"')]")); dropdownValue.click();}
Call this method from your code and pass the value which you want to select
e.g.
new TestClass().selectCombo("Tasmania");
You can try with the xpath //*[@role="option" and text()='New South Wales']