java - 如何从变量中获取字符串值并发送到搜索框
问题描述
'name_asset' 是一个包含字符串值的字符串变量。
我想根据索引将这些值随机发送到搜索框。有什么办法吗?
List<WebElement> Asset = driver.findElements(By.xpath("//div[@class='document-card__details']//h3"));
for (WebElement list_value : Asset) {
name_asset = list_value.getText();
if (name_asset != null) {
System.out.println("the vales are *****" + name_asset);
} else {
System.out.println("Assets count is zero");
}
}
}
解决方案
List<WebElement> Asset = driver.findElements(By.xpath("//div[@class='document-card__details']//h3"));
List<String> assetList= new ArrayList<String>();
for (WebElement list_value : Asset) {
name_asset = list_value.getText();
if (name_asset != null) {
assetList.add(name_asset)
System.out.println("the vales are *****" + name_asset);
} else {
System.out.println("Assets count is zero");
}
}
}
//to access text randomly
Random rand = new Random();
int index= rand.nextInt(assetList.size());
assetList.get(index)
将文本存储到列表并使用随机索引
推荐阅读
- python - 使用 PyCharm 终端在 PyCharm conda 环境中安装依赖项
- sql - Copy csv file to sql table with selected columns
- python - pyQt5 AttributeError: 'bool' 对象没有属性 'txtCustCode'
- html - CSS导航栏重叠和填充问题
- php - 在 php 中调用时,shell 命令不会将错误打印到文件中
- apache-spark - 使用 Argo 工作流程的 K8S Spark
- java - Java - 我如何让 Z 的下一个字母成为 A?
- c++ - 在 docker 容器之间传输时缺少 stdlib 符号
- docker - 无法从 docker 容器内部获取环境
- android - 您的应用包含易受跨应用脚本攻击的 WebView