java - 如何使用 Selenium 和 Java 选择第一个自动建议
问题描述
我正在输入要搜索的名称,然后显示自动建议,但我无法从自动建议中选择第一个选项。
这是带有 TestNG 插件的日食氧气
driver.findElement(By.className("searchfilter")).sendKeys("Abilify");// This is working But after that option selection is not working
driver.findElement(By.cssSelector(".list-group-item:first-child")).click(); // Issue is here
html代码:
<li class="list-group-item list-group-item-action py-3 tabindex fs-1-1 bg-offwhite" id="indexTab1" href="970-ABILIFY" name="ABILIFY - ARIPIPRAZOLE">ABILIFY - ARIPIPRAZOLE</li>
解决方案
1-首先在搜索框中输入您的单词。
2-然后等到您的搜索元素可见或可点击。
WebDriverWait wait = new WebDriverWait(driver, milliseconds);
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//li[@id='indexTab1']"))));
3-然后单击所需的元素
driver.findElement(By.xpath("//li[@id='indexTab1']")).click();
推荐阅读
- haskell - 将 Haskell 转换为模板 Haskell:无法匹配预期类型 ExpQ
- quarkus - quarkus dev with sentry 抛出 java.lang.ClassNotFoundException: com.fasterxml.jackson.core.JsonFactory
- php - 更新到 macOS Big Sur 后,我无法使用 MAMP 连接到我的 PostgreSQL 数据库
- javascript - 如何在html中包含javascript
- excel - 循环优化以逃避硬编码
- ruby-on-rails - Ruby GET响应正文编码?
- google-cloud-functions - 使用 terraform 部署云功能失败 - “请求的功能服务帐户无效”
- python - 如何制定条件或选择日期
- github-actions - GitHub 操作,我如何才能让作业仅在包含代码更改的文件夹中运行?
- java - Spring Boot java.lang.IllegalArgumentException:URL 必须以“jdbc”开头