So I have verification code that contains 7 fields and I have verification code itself. How can I enter this code by number in every field? I tried to do List, but my skills are not that good.
Asked
Active
Viewed 631 times
-2
-
Is it possible to share any screenshot? so that we will able to help you to resolve that issue – UnknownBeast Jun 01 '20 at 11:26
-
added screenshot – kamo Jun 01 '20 at 11:34
2 Answers
0
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();

UnknownBeast
- 979
- 1
- 6
- 13
0
I suggest you to not use a list. For every field you should use another function. Because in time, devs will delete or rename or move.. any field and your test will failed because they do a simple action with just one of field. So I think you should use one function for each field.
typeDigital(String number){ driver.findElemeny(By.css("css"))).sendKeys(number));}
here you will set your number from parapeter. If you have more question about this write me.

Gabri EL
- 1
- 2