如何使用SeleniumWebDriver从autosuggest框中选择元素

如何使用SeleniumWebDriver从autosuggest框中选择元素,selenium,Selenium,我正在发送firepath屏幕截图 我想选择第一个元素并显示在元素文本框中 有人能帮上忙吗?您可以按如下方式更新代码: public class SelectAutoSugggestedValue { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(10, T

我正在发送firepath屏幕截图

我想选择第一个元素并显示在元素文本框中


有人能帮上忙吗?

您可以按如下方式更新代码:

public class SelectAutoSugggestedValue {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.get("http://www.google.com");
        driver.findElement(By.id("gbqfq")).sendKeys("automation tutorial");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        List allOptions = driver.findElements(By.xpath("//td/span[text()='automationtutorial']"));

        for (int i = 0; i < allOptions.size(); i++) {
            String option = allOptions.get(i).getText();
            System.out.println(option);
        }
    }
} 
public类选择AutoSuggestedValue{
公共静态void main(字符串[]args){
WebDriver=newfirefoxdriver();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.manage().window().maximize();
驱动程序。获取(“http://www.google.com");
driver.findElement(By.id(“gbqfq”)).sendKeys(“自动化教程”);
试一试{
睡眠(1000);
}捕捉(中断异常e){
e、 printStackTrace();
}
List allOptions=driver.findElements(By.xpath(“//td/span[text()='automationtutorial']);
对于(int i=0;i
在输入字段框中输入文本时是否会显示自动建议下拉字段?