I am trying to enter text into two text fields and I have tried nearly all element locators, Javascript tricks and the text just does not get entered into the fields. The test passes but I can see that no text has been entered.
The site I'm practicing on is https://www.chegg.com/auth?action=login&redirect=http%3A%2F%2Fwww.chegg.com%2F&reset_password=0
The two fields are email and password field.
This should work but doesn't, providing a snippet of the code:
WebElement emailField = driver.findElement(By.name("email"));
WebElement passwordField = driver.findElement(By.name("password"));
emailField.sendKeys("whatever");
passwordField.sendKeys("whatever");
What am I doing wrong?
Actually in your provided website, two elements are present using By.name()
locator where first is invisible and second is visible and you are interacting with first element which is invisible on the page. That's why you are in trouble, you should try some different locator to locating correct element, I would suggest you try using By.cssSelector()
as below :-
WebElement emailField = driver.findElement(By.cssSelector(".C-common-auth-signin-component input[name = 'email']"));
emailField.sendKeys("whatever");
WebElement passwordField = driver.findElement(By.cssSelector(".C-common-auth-signin-component input[name = 'password']"));
passwordField.sendKeys("whatever");