Webdriver "sendkeys" method doesn't enter password correctly Webdriver "sendkeys" method doesn't enter password correctly selenium selenium

Webdriver "sendkeys" method doesn't enter password correctly


The SendKeys method is going to send characters to whichever WebElement object you called it on, in this case, query. Even after tabbing to the next object, it'll still be sending keys to the query element. In my experience, using keys (such as tab) to jump between elements tends to be inconsistent and unreliable. Instead, try something like this:

WebElement userNameField = driver.findElement(By.id("userNameTextBoxId"));WebElement passwordField = driver.findElement(By.id("passwordTextBoxId"));userNameField.sendKeys("myusername");passwordField.sendKeys("mypassword");

If you don't have ids on the text boxes, there are several other identifiers you can use such as classname and xpath (although I've had bad experience with xpath in selenium -- use id's whenever possible).