Command in Selenium Webdriver for initiating a mouse click

Currently, I am in the process of writing tests for a Java application that has been created with the Vaadin framework. To conduct these tests, I have opted to utilize the Robot Framework. In certain instances, I must implement robot framework commands such as execute javascript.

For instance, when locating a component, the following command is executed:

execute javascript    document.getElementById('button-create').click()

This method works seamlessly. The use of primitives like Click Element is ineffective due to Vaadin not waiting for the entire page to load resulting in some ids being unassigned at runtime.

Regrettably, the design of this specific application dictates that some components respond to the event click, while others require the event mousedown. When interacting with the Java console in Chrome, executing the following command proves successful:

    document.getElementsByClassName('table-cell-wrapper')[1].mousedown();

producing the desired action without any issues. Unfortunately, attempting to carry out the same action within the robot framework environment yields an error:

    execute javascript    document.getElementsByClassName('table-cell-wrapper')[1].mousedown();

The error message encountered reads as follows:

Executing JavaScript:
document.getElementsByClassName('table-cell-wrapper')[1].mousedown();
20131029 12:22:12.445 :  INFO : </td></tr><tr><td colspan="3"><a href="selenium-    screenshot-1.png"><img src="selenium-screenshot-1.png" width="800px"></a>20131029 12:22:12.453 :  FAIL : 
WebDriverException: Message: u'document.getElementsByClassName(...)[1].mousedown is not a function' ;

Therefore, the question arises... how can I successfully trigger the mousedown event on a specific element using Javascript and Webdriver?

The current environment details are as follows:

RIDE 1.2.1 operating on Python 2.7.5. 
Robot Framework 2.8.1
Library           Selenium2Library
Library           Screenshot
Library           Dialogs
Library           Collections

Thank you in advance.

Answer №1

When using the Execute Javascript keyword from Selenium2Library, keep in mind that the code will be executed in the context of the Selenium object itself by default. This means that 'this' will refer to the Selenium object. If you want to reference the window of your application, use 'window', for example: window.document.getElementById('foo')

It's important to include window. as needed in your code.

The function mousedown() is not a pure JavaScript function. While JQuery has one, there is also an event called mousedown in plain JS.

If you encounter situations where an element does not exist after the page loads, causing a failure when trying to Click Element like so:

Click Element    foobar

You can utilize the Wait Until Page Contains Element keyword along with creating your own Press Element keyword for added utility:

Press Element    ${locator}
    Wait Until Page Contains Element    ${locator}
    Click Element    ${locator}

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

How can background wait for executescript in a Chrome Extension?

I'm currently encountering an issue while developing my first Google Chrome Extension. In my background.js script, I have a scenario where I call script.js every second. Here's a simplified version of the code: script.js: /* Some code */ if (co ...

Failed attempt to perform Ajax requests for REST API data

I am currently working on developing an application that requires a login through a REST API to retrieve a session id. To achieve this, I have set up a button that triggers a JavaScript function for making an AJAX call to authenticate the user. The result ...

The issue with ng-change is causing the previously selected drop down option to be cleared

After successfully implementing live searching with ng-change, I encountered an issue with a pre-selected drop-down box. Despite setting the selected="selected" attribute to make option three the default selection, the drop-down box jumps to the top optio ...

Having trouble terminating the session with the authentication provider SSO on Node JS

I'm struggling with ending the session properly when a user makes a request to my /logout endpoint. I want to clear the session and require the user to log in again via SSO. Currently, after an initial login, I remain logged in without needing to re-e ...

Accessing data from the database in order to present it visually as a line graph

I am struggling to efficiently display data from my database on a line graph. Currently, I am executing individual queries for each year to retrieve specific results, which is making the code messy. Is there a more streamlined approach to fetch and display ...

Manage multiple sessions at the same time

In a specific scenario, we face the need to manage multiple sessions similar to Google Accounts. Users should be able to add different accounts in separate tabs, each with its own unique content. For example, user1 may be logged in on Tab1 while user2 is l ...

Encountering an issue with Angular routing: Cross-origin requests are restricted to specific protocol schemes, such as HTTP

I encountered an error while working on angular routing. Below is my HTML code snippet: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <script src= ...

Tips for embedding dynamic JSP pages from a different server into your own JSP page

I'm currently working on a project where I need to dynamically incorporate an HTML snippet into a webpage. The course information is stored on one server, and I want other servers to be able to include it using just a single line of code. If the file ...

One might encounter undefined JSON keys when attempting to access them from a script tag

During my attempts to load a specific Json using an Ajax GET request and then parsing it, I encountered an issue when trying to access the Json key from an HTML script tag, as it returned as undefined. To troubleshoot this problem, I decided to log all th ...

How do I incorporate global typings when adding type definitions to an npm module?

Suppose I create a node module called m. Later on, I decide to enhance it with Typescript typings. Luckily, the module only exports a single function, so the m.d.ts file is as follows: /// <reference path="./typings/globals/node/index.d.ts" /> decl ...

Is there a way to properly structure the json data displayed in my network tab on Chrome?

After sending an http request to my backend, I received a json response in the network tab. However, the format of the json is unreadable. To clarify, here is a screenshot: https://i.stack.imgur.com/RBiTd.png Currently using Chrome, I am seeking assistanc ...

Discovering the central point within an SVG path

I am currently working with a path that is part of a group and using Jquery to locate the specific path. My goal is to find the midpoint of that path. I came across an example here. However, when attempting to use .getTotalLength(); or .getPointAtLength(), ...

Is it considered fashionable to utilize HTML5 data attributes in conjunction with JavaScript?

Currently, I am utilizing HTML5 data attributes to save information such as the targeted DOM element and to initialize events using jQuery's delegation method. An example of this would be: <a href="#" data-target="#target" data-action="/update"> ...

What's the point of using defer() in Node.js Q promises when you have the option to simply use this

I had a plan in mind: somePromiseFunc(value1) .then(function(value2, callback) { // insert the next then() into this function: funcWithCallback(callback); }) .then(function(dronesYouAreLookingFor){ // Let's celebrate }) .done(); Unfortun ...

Malfunctioning string error in Django view caused by boolean inconsistencies

Looking to extract variables from a post request made by Javascript. Upon inspecting the received variables in my view, I found the following: >>> print request.body {"p":"testprd","cash":false,"cheque":true,"debit":false,"credit":true} The valu ...

Using Nestjs to inject providers into new instances of objects created using the "new" keyword

Is it possible to inject a provider into objects created by using the new keyword? For instance: @Injectable() export class SomeService { } export class SomeObject { @Inject() service: SomeService; } let obj = new SomeObject(); When I try this in my t ...

How can I effectively display a blank menu item for the SelectField component in Material-UI within a React application?

I am using the select-field component from the material-ui framework version 0.15.4 with React version 15.4.0. I am attempting to add a blank menu-item to the select-field in order to allow for deselecting a value in the dropdown field when clicked. Howeve ...

Use an external javascript file in AngularJS if permitted

To ensure that my HTML page only loads an external JavaScript file when the variable $scope.jsallowed is set to true, I attempted the following code implementation within my AngularJS based page: <script src="assets/js/slider.min.js" data-ng-if="jsallo ...

Extra spaces within the source code visible after the page has been processed by Angular

Within my angular application, I am retrieving a list of addresses from a service that provides an object structured like this: { Flat: "10B", BuildingName: "Some Building", Line: "10B Some Building Road Town POST CODE", Postcode: "POST CODE", ...

"Encountering an 'Unexpected string' error when trying to implement a

$('.star').mouseover(function (){ var starIndex = $(this).index()1; $(this).parent().css("background-position", "0 -" + (32 * starIndex) + "px"); }); $('.star-rating').mouseout(function (){ var originalResult = $(this).attr ...