I am currently working on creating an automated test for a Single Page Application built with VueJs. When I click on the registration button, a form is loaded onto the page with various elements. However, since the elements are loaded dynamically, they are not immediately present on the page. Although adding a driver.sleep function after clicking the registration button solves the issue, I have been exploring alternative solutions. I've experimented with ImplicitWaits and elementIsEnabled methods, but so far, I haven't achieved the desired results. Here is a snippet of my code:
const { Builder, By, Key, until } = require('selenium-webdriver')
async function test() {
const driver = await new Builder().forBrowser('chrome').build()
await driver.get('https://dez.dev.dav.med.br/login')
let element = (By.xpath('//*[contains(text(), "Register")]'))
let query = await robo(element, driver)
await query.click()
await driver.sleep(2000)
element = (By.xpath('//*[contains(@title, "Name")]'))
query = await robo(element, driver)
await query.sendKeys("TestingVictor2")
// Additional code...
}
test()
async function robo(element, driver, TIMEOUT=10000){
const locator = await driver.wait(until.elementLocated(element, TIMEOUT))
const query = await driver.wait(until.elementIsVisible(locator, TIMEOUT))
return query
}