<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
Try using -
String options = driver.findElements(By.xpath("//li//text()"));
System.out.println(options.getText());
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());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.