0
<ul class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content category-choices" id="ui-id-3" tabindex="0" style="display: none; top: 285.516px; left: 524.5px; width: 300px;">
<li data-custom-text="location__text" class="ui-menu-item" id="ui-id-50" tabindex="-1">Car Seats and Baby Carriers<div> in <span>Baby and Kids</span> </div></li>

I used below code

String options =driver.findElements(By.xpath("//li//div//span"));
System.out.println(options.getText());

Actual Output: Baby and Kids

Expected output: Car Seats and Baby Carriers in Baby and Kids

kavya s
  • 19
  • 1
  • 1
  • 3

2 Answers2

0

Try using -

String options = driver.findElements(By.xpath("//li//text()"));
System.out.println(options.getText());
0

You went too deep into your nested tag also options is one element and not multiple and is of webelement type.

WebElement options = driver.findElement(By.xpath("//ul/li[class='ui-menu-item']"));

Then this

System.out.println(options.getText());
Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32