Issue with Selenium webdriver's element.click() method not operating as anticipated in Chrome while using Mocha framework

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 &amp;&amp; usr.password) || attempt_Error)}" ng-if="!reset_Hash &amp;&amp; !forgotMode" class="btn btn-prim ng-scope" style=""> Log in</button>

Expected behavior (as observed manually):

  1. On mouseover, the button changes to color1.
  2. On click, the button changes to color2.
  3. If correct email and password are provided, upon release it should navigate to the homepage.

Actual execution showed:

  1. The button changes to color2.
  2. No action occurs.
  3. 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",

Answer №1

After encountering the persistent 403 errors, I resorted to a somewhat unconventional approach...

driver.get('http://localhost:9000');
driver.navigate().refresh();

This sequence now initiates navigation to localhost:9000 followed by a repeat visit, culminating in a refreshing action. Surprisingly, this has effectively resolved the issue at hand.

The rationale behind this workaround remains unclear, yet the results speak for themselves.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Updating two separate <DIV> elements with a single AJAX request

Can two different targeted DIVs be updated simultaneously using a single ajax call? Consider the index.html code snippet below: <script> xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.rea ...

What causes Selenium to halt its execution once logged into a page?

We were able to successfully log into the application using Selenium, but we are encountering a problem where Selenium stops working and doesn't proceed further. Below is the code snippet that we have used to access the application: public class tes ...

One creative method for iterating through an array of objects and making modifications

Is there a more efficient way to achieve the same outcome? Brief Description: routes = [ { name: 'vehicle', activated: true}, { name: 'userassignment', activated: true}, { name: 'relations', activated: true}, { name: &apos ...

"Unlocking the Power of mediaElementjs: Easy Steps to Accessing the Player Instance

I'm facing a small issue with the MediaElement.js player. To access the player instance, I usually use the following code (which works in HTML5 compatible browsers): // Retrieve player this.playerId = $('div#shotlist-player video').att ...

What is the best way to restrict the creation of objects in a JavaScript list?

Experiencing a fun challenge with HTML coding! Take a look at my ordered list in HTML: <ol id="myList"> <li>Tea</li> <li>Milk</li> <li>Water</li> </ol> <button onclick="myFunction()">Try it</ ...

When querying the model, the result may be undefined

I'm encountering an issue where I can't access the content of an array of documents in my model and it's returning undefined. Here is the model structure (Project.js): var mongoose = require('moongoose'); var Schema = mongo ...

The JQUERY Uncaught Error: Syntax error message popped up when trying to access an unrecognized expression on the javascript: void(0)

I've encountered an issue after upgrading to jQuery 3.4.1 while using bootstrap 3. The console keeps showing this error: Uncaught Error: Syntax error, unrecognized expression: # Here is the section of code causing the error: <div class="btn-grou ...

Avoid wrapping elements

Is there a foolproof method or best practice to prevent an HTMLElement from wrapping? Specifically, I'm referring to elements with relative positioning. One possible solution could be using absolute elements and adjusting their left position based on ...

Creating movement effects for a line on an HTML5 canvas following a previous animation

I am facing an issue where my straight line starts animating towards the circle right at the beginning of page load. I am struggling with finding the logic to make the line animate in the opposite direction after the first animation is completed (which is ...

Sharing React components in projects

Two of my upcoming projects will require sharing components such as headers, footers, and inputs. To facilitate this, I have moved these shared components into a separate repository, which has been working well so far. In the common repository, I have set ...

What is the process for creating a custom Javascript function that can seamlessly integrate with other Javascript libraries?

Is there a way to create a method that can be linked or chained to jQuery methods and other library methods? For example, consider the following code snippet: var Calculator = function(start) { var that = this; this.add = function(x) { start = start ...

Activate the Alert (https://material-ui.com/components/alert/#alert) starting from the React component at the bottom of the hierarchy

When it comes to alerts, a normal alert is typically used like alert("message to be displayed");. However, I prefer using material UI Alerts which return a JSX component. For example: <Alert severity="success">This is a success alert — check it out ...

Angular-oauth2-oidc does not successfully retrieve the access token when using OAuth2 and SSO

Here's an issue I'm facing: I've been attempting to integrate SSO and OAuth2 flow using angular-oauth2-oidc. When testing with POSTMAN and ThunderClient in VS Code, I managed to receive the correct response (the access_token). However, I am ...

Tips for delaying the execution of numerous ajax success callbacks?

In my JavaScript code, I am facing the following situation: call_A(success_A) call_B(success_B) function call_A(success){ // make ajax request success(result) } function call_B(success){ //make ajax request success(result) } function success_A(){ ...

Ways to add a string to an array as a labeled object in javascript?

Is there a way to manipulate the array in imageCollection to achieve the format of the array in carouselPhotos as shown below? export default class HomeScreen extends Component { state = { imageCollection: [ { name: "P ...

Issues with routeparams are preventing ng-repeat from functioning properly, without any response or resolution

For my shoppingCart project, I am working on dynamically bringing data into views. I am using routeParams in template.html but facing an issue. The data is arriving normally as checked via ng-href="#/store/{{something.name}}/{{ child.name }}" but it isn&ap ...

Automatically conceal a div once an iframe reaches a specific height

When a user schedules an appointment on our website, it triggers a change in the height of an iframe. I want to automatically hide the section above the iframe once the iframe's height has changed. Currently, I have implemented the following code whic ...

Enhance your dynamic php page with the use of a light box feature

Hey, I have created a PHP page that dynamically reads images from a folder and displays them on a gallery page. However, I am facing some issues - I am unable to link an external CSS file and I have to include all the CSS within the HTML. Additionally, I c ...

capturing the value of a button during the onChange event

I'm currently trying to retrieve the button value within an onChange event. My goal is to then bind this value to state, but unfortunately, I am receiving an empty value. <button onChange={this.handleCategoryName} onClick={this.goToNextPage}> ...

Redis data retrieval is successful on the second attempt

I am utilizing a Redis database along with express routing to create an API. My stack includes node.js and ioredis as well. The process involves connecting to Redis, fetching keys related to a specific date, and then retrieving the data associated with th ...