Вы можете найти выбранный текст опции и список всех доступных опций, как показано ниже.
Пожалуйста, используйте приведенную ниже логику в вашем коде
Код:
//If none of the option is selected, then exception will be thrown and to avoid this we can use findElements method
List<WebElement> radioButtonSelectedList=driver.findElements(By.xpath("//*[@class='radio-checked']//parent::*//span"));
String selectedValue="";
ArrayList<String> optionsList = new ArrayList<String>();
if(radioButtonSelectedList.size()!=0){
//If the button is selected, then we can get the selected option text
selectedValue=radioButtonSelectedList.get(0).getText();
//To get all the available Options
List<WebElement> optionsElement=driver.findElements(By.xpath("//ul[@class='custom-ul']//span"));
for(WebElement element: optionsElement){
optionsElement.add(element);
}
}
else{
System.out.println("None of the option is selected");
}
System.out.println("Available Options :"+optionsList);
System.out.println("Selected Option :"+selectedValue);