I have this code where I fill 2 fields and then click on login button:
driver.findElement(By.xpath(numberInputXPath)).sendKeys(number);
driver.findElement(By.xpath(passwordInputXPath)).sendKeys(password);
driver.findElement(By.xpath(loginButtonXPath)).click();
My problem is that sometimes the login button is pressed with fields incompletely filled. The pattern on incompleteness seems random to me. I have 11 numbers at string number
and my password
is 8-alphanumeric-char long. Sometimes the fields are completely filled, sometimes the first one is incomplete by half and password
is entirely filled and vice-versa. Sometimes they are completed normally and my login is successfully done. Besides thread sleeping and this solution, how can I wait only until my fields are filled?
EDIT
I didn't have time to try the answers' solutions and I will ASAP, but I'm trying to automate login at this page. I wait until Selenium recognizes up right Login
button, click on it and then fill the fields as wrote above. I notice that every time sendKeys
is executed, the page still has the loading icon on Chrome tab. Always. So I assumed that some JS is always loading at the time of writing.