gpt4 book ai didi

java - 如何使用 Selenium 填写自动完成输入框? (为什么自动输入不加载自动完成选项,而手动输入却加载?)

转载 作者:搜寻专家 更新时间:2023-10-31 20:28:58 25 4
gpt4 key购买 nike

以下代码测试网页的自动完成框:

public class Test {

public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","chromedriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www..............com");
driver.switchTo().frame("mainFrame");

WebDriverWait waitst = new WebDriverWait(driver, 120);
waitst.until(ExpectedConditions.visibilityOfElementLocated(By.name("sourceTitle")));

WebElement sourceTitle = driver.findElement(By.name("sourceTitle"));
WebElement small = driver.findElement(By.cssSelector("li#nameExampleSection label + small"));
sourceTitle.sendKeys("Times");
Thread.sleep(5000);
Actions actions = new Actions(driver);
actions.click(small).perform();

}

}

为什么自动建议框不加载? 重要提示:尝试手动输入“......” ...自动完成框将加载得很好!!!那么,为什么 cssSelector 不起作用,为什么它不加载自动完成框?

为什么自动输入不允许自动完成选项,但手动输入却允许???

PS:我也尝试了fireEventsendKeys,但没有任何效果。

最佳答案

我尝试了您的代码,它的功能与手动演练完全相同。 “美联社”仅返回“不匹配,请尝试来源”。然后在您的代码中尝试单击下一个表单列表项,而不是结果弹出窗口。自动提示弹出窗口动态填充在位于输入表单下方的 html 页面顶部。以下代码确实选择了下拉列表中的第一个选项。

@Test
public void test() throws InterruptedException {
WebDriver driver = new ChromeDriver();
driver.get("http://www.lexisnexis.com/hottopics/lnacademic/?verb=sf&sfi=AC00NBGenSrch");
driver.switchTo().frame("mainFrame");

WebDriverWait waitst = new WebDriverWait(driver, 0);
waitst.until(ExpectedConditions.visibilityOfElementLocated(By.name("sourceTitle")));

WebElement sourceTitle = driver.findElement(By.name("sourceTitle"));
sourceTitle.sendKeys("Times");
Thread.sleep(5000);
WebElement firstItem = driver.findElement(By.xpath("//*[@class='auto_suggest']/*[@class='title_item']"));
firstItem.click();
}

关于java - 如何使用 Selenium 填写自动完成输入框? (为什么自动输入不加载自动完成选项,而手动输入却加载?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17741060/

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