【发布时间】:2019-08-23 07:53:11
【问题描述】:
如何在 selenium 中为该网站“https://www.goibibo.com/”处理“来自”和“目的地”框中的自动建议。 请帮忙
基本的方法我累了,但无法获得自动建议下拉的X路径
无法点击下拉菜单
package basic;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class goibibo {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
WebDriver driver = new ChromeDriver();
driver.get("https://www.goibibo.com/");
new WebDriverWait(driver, 20)
.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='gosuggest_inputSrc']")))
.sendKeys("Mum");
List<WebElement> myList = new WebDriverWait(driver, 20).until(
ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//*[@id=\"react-autosuggest-1\"]")));
for (WebElement element : myList) {
if (element.getText().contains("Mumbai"))
;
element.click();
}
}
}
【问题讨论】:
-
可能是 xpath 的原因,请尝试选择它会起作用,您应该尝试一下。
-
//*[@id=\"react-autosuggest-1\"] 这是下拉列表的 x 路径,但仍然无法正常工作,请选择其他位置。不知道这不起作用:(
-
等待我正在处理它会返回答案
标签: selenium selenium-webdriver autosuggest