java - 带有 Java 的 Selenium Webdriver(Angular 应用程序)
问题描述
我编写了下面的代码,用于从下拉列表中选择提到的值。
在这里,我只想@data-option-array-index=1,3,5,9,28,34
从下拉列表中选择这些。
我想使用一种数组或循环,它只为这些选定的值运行。但我做不到。
element=driver.findElement(By.xpath("//li[@class='search-field']"));
element.click();
element=driver.findElement(By.xpath("//li[@data-option-array-index='1']"));
element.click();
String text=driver.findElement(By.xpath("//li[@class='search-choice']")).getText();
System.out.println("Element text is: "+ text);
解决方案
使用 findElements,
List<WebElement> choises=driver.findElements(By.xpath("//li[@class='search-choice']"));
List<String> listValues= new Arraylist<String>();
for(WebElement choise : choises){
listValues.add(choise.getText());
}
推荐阅读
- c - 将两个指向同一个联合成员的指针传递给函数是否违反了严格的别名规则?
- regex - RegEx 强制执行典型的 Forename 格式
- javascript - 将数组中的树转换为使用 React Flow 和 Dagre 显示
- ios - 如何显示文本取决于 SwiftUI 中的 switch case?
- solana - 索拉纳主播:如何及时转发?
- c# - 从 SQL Server 的 JSON 格式脚本在 ASP.NET Core 中将地址显示为列表
- next.js - storybook + nextjs 路由器:NextContext.Provider 未定义,请添加到 parameters.nextRouter.Provider
- hyperledger-fabric - Hyperledger Fabric Java Chaincode 可以在没有 docker 的情况下安装和运行吗?
- python - R / Python中的Stata图
- jmeter - BeanShell Sampler 是否支持 JMeter 中的 http 请求和 tcp 响应?