Currently, I am using Selenium to automate some testing for our company's website, but encountering issues along the way.
TestItemFromSearch: (driver, part, qty) => {
Search.SearchItem(driver, part);
driver.findElement(By.id('enterQty')).findElement(By.tagName('input')).sendKeys(qty);
driver.findElement(By.linkText('Personalize')).click();
//This redirects to a new page.
driver.wait(() => {
}, 1000).then(() => {
}, //TODO: This sucks. Fix it.
Login.Login(driver, Logins.username, Logins.password));
driver.findElement(By.className('selectDesignButton')).click();
}
At times, when Selenium is directed to a new page, I have to employ the wait function. However, regardless of the condition I set, it fails to find that condition and results in failure. To tackle this, I have resorted to using the Reject method to execute desired actions (like Login.Login).
I might need to repeat this process within the same test as it navigates through multiple pages, leading to messy and unreadable code.
How can I make Selenium properly wait? If I use the following:
driver.wait(()=>{}, 1000)
it ends up waiting indefinitely. Even if I add a return statement, it instantly fails without waiting at all.