I am using selenium with Java. I am unable to get text from html element that is a combobox. Every time I am getting blank text for the selected value in combobox.
Below is my html structure for combobox.
<ul id="servicetype-cave" class="z-combobox-content" style="height: auto; width: auto;">
<li id="zk_comp_140" class="z-comboitem">
<li id="zk_comp_141" class="z-comboitem">
<li id="zk_comp_142" class="z-comboitem">
<li id="zk_comp_143" class="z-comboitem">
<li id="zk_comp_144" class="z-comboitem z-comboitem-selected">
<span class="z-comboitem-image"/>
<span class="z-comboitem-text">Bill Grouping Service</span>
</li>
<li id="zk_comp_145" class="z-comboitem">
<li id="zk_comp_146" class="z-comboitem">
<li id="zk_comp_147" class="z-comboitem">
<li id="zk_comp_148" class="z-comboitem">
<li id="zk_comp_149" class="z-comboitem">
<li id="zk_comp_150" class="z-comboitem">
</ul>
I have used below xpath for the element
@FindBy(xpath = "//ul[@id='servicetype-cave']/li[contains(@class,'z-comboitem-selected')]/span[@class='z-comboitem-text']")
public WebElement selectedServiceName;
public void selectService {
// Selecting an option from dropdown
WebElement tempEle = driver.findElement(By.xpath("(//div[@id='servicetype-pp']//span[2])[3]"));
commonFunctions.clickElement(tempEle);
String strtemp = selectedServiceName.getText();
System.out.println("Selected Service: " + strtemp);
}
Please help.
TIA.