Skip to content

Select option from Combobox using visible text

I’m working with Marathon Java Driver for automating a JavaFX application. I have to select an value from a combobox based on visible text. Currently, I get all the options using .::all-options and looping through each item to get the text and compare it with the required text option. However, the time taken is high based on the number of options.

Is there any other way to select the value from combobox using visible text – something like driver.findElement(By.csslocator("combox1::value"));?

Answer

  1. Get the combobox element

    WebElement comboBoxElement = driver.findElement(By.csslocator("$comboBox_properties"));
    
  2. Now select the desired value:

    coboBoxElement.findElement(By.csslocator(".::call-select('$value$')"))
    

Example:

coboBoxElement.findElement(By.csslocator(".::call-select('Option10')"))