While testing the log in feature of a website, I encountered an issue where the .click()
method did not perform as expected despite being able to locate the Login button.
Here is the relevant JavaScript test code:
driver.sleep(1000)
driver.findElement(By.name('email')).sendKeys(fakeEmail);
driver.findElement(By.name('password')).sendKeys(fakePassword);
driver.sleep(5000);
driver.findElement(By.xpath("//button[@type='submit']")).isEnabled()
.then(function(isEnabled) {
console.log(isEnabled) // prints true
var el = driver.findElement(By.name('password'));
el.sendKeys(webdriver.Key.ENTER); //method 1
})
//note: these xpaths are correct. I am able to get inner text, for example
driver.findElement(By.xpath("//button[@type='submit']")).sendKeys(webdriver.Key.ENTER); //method 2
driver.findElement(By.xpath("//button[@type='submit']")).click(); //method 3
Now, let's take a look at the code in the login button HTML:
<button type="submit" ng-disabled="attempt_Error" ng-class="{'disabled': (!(usr.email && usr.password) || attempt_Error)}" ng-if="!reset_Hash && !forgotMode" class="btn btn-prim ng-scope" style=""> Log in</button>
Expected behavior (as observed manually):
- On mouseover, the button changes to color1.
- On click, the button changes to color2.
- If correct email and password are provided, upon release it should navigate to the homepage.
Actual execution showed:
- The button changes to color2.
- No action occurs.
- The window remains open, and even manual clicking on the button doesn't trigger any response.
I have tried implementing Methods 1-3 from my JS code individually and together, but none provide the desired outcome. Even attempting to navigate to the homepage after this process does not result in successful log in.
Hence, my question arises: why is element.click()
not functioning according to expectations?
Edit: Despite confirming that the login function was called through a console log, I noticed something peculiar - there was a "Failed to load resource: the server responded with a status of 403 (Forbidden)" error in the console! Subsequently, continuous clicking of the button resulted in
angular.js:8632 POST http://localhost:9000/api/session 403 (Forbidden)
. Interestingly, this error does not occur when performing the same actions manually. Any insights into this discrepancy?
Versions:
"chai": "^4.1.0",
"chai-as-promised": "^7.1.1",
"chromedriver": "^2.31.0",
"mocha": "^3.4.2",
"selenium-webdriver": "^3.5.0",