java - 如何在字段 /selenium 中逐位输入数字
问题描述
所以我有包含 7 个字段的验证码,我有验证码本身。如何在每个字段中按数字输入此代码?我试着做List,但我的技能不是那么好。
解决方案
It is totally dependent on how you application looks and what the DOM structure is. I could help you with the following piece of code that shows how you can automate the verification code field. Execute the below code and see how it works.
driver.get("https://codepen.io/DaniRC/pen/PowwwjZ");
List<String> data = new ArrayList<String>();
data.add("5");
data.add("4");
data.add("3");
data.add("5");
int counter = 0;
driver.switchTo().frame("result");
List<WebElement> elements = driver.findElement(By.id("form")).findElements(By.xpath("input[@type='text']"));
for(WebElement element : elements)
{
element.sendKeys(data.get(counter));
counter++;
}
Thread.sleep(10000);
driver.close();
推荐阅读
- javascript - 访问 react 组件中的 body 以使用 scrollspy
- java - 嵌套HashMap值乘法-Java
- visual-studio - Azure Function 1.x 和 VS17 的 Nuget 问题
- python - 是否可以直接访问原始 numpy 字节?这里的“直接”一词的意思是“不复制”
- bash - 使用 pod 名称执行 Kubernetes pod
- kdb - 如何在 kdb 中将时间戳转换为日期格式
- r - tidyverse 中的 Slice_max
- reactjs - 无法创建反应应用程序,有线错误?
- python - 循环期间打印有问题
- r - R中带有向量和矩阵的自定义函数