【发布时间】:2021-09-05 02:08:07
【问题描述】:
我试图使用 selenium webdriver java 在 GoIbibo 中自动进行航班预订。当我们输入“来自城市”的值时,会显示一个列表作为自动建议。
但我无法使用 xpath 检测自动建议中的元素。由于无法检查列表,因此也无法找到显示的列表的确切 xpath 或 id。我已经使用下面的代码来查找显示的元素,但这也不起作用。
driver.findElement(By.id("gosuggest_inputSrc")).sendKeys("Dublin (DUB)");
WebDriverWait nw = new WebDriverWait(driver, 30);
nw.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='gosuggest_inputSrc']//following-sibling::input")));
List<WebElement> orgins = driver.findElements(By.xpath("//*[@id='gosuggest_inputSrc']//following-sibling::input"));
for (WebElement we : orgins){
System.out.println(we.getText());
请帮助识别自动建议列表中的元素并从自动建议列表中选择需要的元素。使用的网址-https://www.goibibo.com/
【问题讨论】:
-
能给我网址试试吗?
-
@Rajagopalan- URL- goibibo.com
-
现在能够识别列表但无法从列表中选择值。请在下面找到代码'WebDriverWait nw = new WebDriverWait(driver, 30); driver.switchTo().frame("notification-frame-22a3446b3"); nw.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.fl_shAutosgBox:nth-child(1)"))); List
orgins = driver.findElements(By.cssSelector("div.fl_shAutosgBox:nth-child(1)")); for (WebElement we : orgins){ System.out.println(we.getText()); if (we.getText().equals("都柏林 (DUB)")){ we.click();' -
尝试使用javascript执行器来选择
标签: java selenium selenium-webdriver webdriver automated-tests