gpt4 book ai didi

java - 如何处理selenium中的自动建议

转载 作者:行者123 更新时间:2023-11-30 03:53:17 24 4
gpt4 key购买 nike

//for source
WebElement from= driver.findElement(By.id("autocomplete_source"));
from.clear();
from.sendKeys(FromCity);
Thread.sleep(3000);
Actions builder=new Actions(driver);
builder.moveToElement( from.findElement(By.xpath("//*[@class='acResults']/ul/li[1]/span"))).click().build().perform();

//for destination

WebElement to=driver.findElement(By.id("autocomplete_dest"));
to.clear();
driver.findElement(By.id("autocomplete_dest")).sendKeys(ToCity);
builder.sendKeys(Keys.ARROW_DOWN).click().build().perform();
WebDriverWait wait=new WebDriverWait(driver, 90);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//* [@class='acResults']/ul/li/span")));
to=driver.findElement(By.cssSelector(".acResults>ul>li>span"));
Thread.sleep(2000);
to.click();

/* 有两个文本框源和目标,源正在处理,但目标不起作用。 当我在目的地列表中经过金奈时,显示向下箭头正在工作,但它没有选择并且给出错误定位器不可见 */

最佳答案

提供 HTML。我在 redbus.in 上尝试了自动建议,并且无需使用 Action 类即可工作。这是一个适用于我在 FF/Chrome 上的代码 -

driver.get("http://www.redbus.in/");
driver.findElement(By.xpath(".//*[@id='txtSource']")).sendKeys("pune");
driver.findElement(By.xpath(".//*[@id='txtDestination']")).sendKeys("Chennai");

请提供 url 或 html,以便我们深入研究。

下面的代码适用于我的 FF( http://in.via.com/bus-tickets)-

driver.get("http://in.via.com/bus-tickets/");
WebElement from = driver.findElement(By.xpath(".//*[@id='autocomplete_source']"));
WebElement to =driver.findElement(By.xpath(".//*[@id='autocomplete_dest']"));
from.clear();
from.sendKeys("Pune");
to.clear();
to.sendKeys("Chennai");
WebDriverWait wait=new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("html/body/div[9]/ul/li")));
driver.findElement(By.xpath("html/body/div[9]/ul/li")).click();

//点击提交

driver.findElement(By.xpath(".//*[@id='bookingDiv']/div[21]/input")).click();

关于java - 如何处理selenium中的自动建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23863425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com