1

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"));?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

1
  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')"))
Aditya Karra
  • 151
  • 1
  • 7
  • Hi Aditya, Sorry I couldnt' reply sooner. I have initially solved by getting the whole content, splitting it and then using an for loop to compare the text and getting the id. Yours is the most simple and straight forward answer... – karthik110885 Apr 26 '21 at 06:32
  • `String combocontent = combo.getAttribute("content").replaceAll("[\\[\\]]", ""); String [] array = combocontent.split("\",\""); System.out.println(combocontent); for(int i = 0; i < array.length; i++) { if (i==0 || i == array.length-1) { array[i] = array[i].replaceAll("[\"]",""); } if(testdata.equalsIgnoreCase(array[i])) { combocontentid = i+1; String optionvalue = "combo-box::nth-option("+combocontentid+")"; WebElement option = combo.findElement(By.cssSelector(optionvalue));option.click(); option.sendKeys(Keys.ENTER); break; }}` – karthik110885 Apr 26 '21 at 06:36