I am a newcomer to this industry and am facing a challenge with testing the process of entering the correct username and password using Selenium Webdriver. The current method of creating this process without a loop is extremely lengthy and monotonous. Here's an example:
let element0 = driver.findElement(By.id("login"));
element0.click();
element0.sendKeys("admin");
await driver.sleep(1500);
element0.clear();
I need a loop that will take the first element from the array of logins and passwords, insert them into the corresponding fields, check them, delete them, etc.
I attempted to use a for loop, but it outputted all elements of the array.
async function fillLoginPassBox() {
let element0 = driver.findElement(By.id("login"));
let element1 = driver.findElement(By.xpath('//*[@id="password"]'));
let logins = ['test0', 'test1', 'admin'];
let passwords = ['test0', 'test1', 'admin'];
for(let key in logins) {
element0.sendKeys(logins[key]);
element0.click();
element0.clear();
console.log(logins[key]);
}
// element0.click();
// element0.sendKeys("admin");
await driver.sleep(1500);
element1.click();
element1.sendKeys("admin");
await driver.sleep(1500);
return element1, element0;
}