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

generate code to automatically output the content of a website

I'm in the process of creating a program that automatically navigates to a website and prints a page. Unfortunately, I'm encountering difficulties in getting it to function properly. I've attempted using the selenium chrome driver, but with ...

Assistance with Javascript Objects Using JSON and AJAX

Currently, I am utilizing Ajax to retrieve data from my Json file. A problem I am facing is that in one particular div of my html, I need to include both a heading and a paragraph. I attempted to create a property like so: "headingpara": "<h1> blah ...

Automatically update the page when there is a change in the status of the

$counter = "SELECT countnumber FROM onairsystem WHERE id='1'"; $counterresult = $connection->query($counter); $rows = $counterresult->fetch_array(); $number = $rows['countnumber']; Is there a way to automatically refresh the we ...

Ways to access configuration settings from a config.ts file during program execution

The contents of my config.ts file are shown below: import someConfig from './someConfigModel'; const config = { token: process.env.API_TOKEN, projectId: 'sample', buildId: process.env.BUILD_ID, }; export default config as someCo ...

Error encountered in main thread: Illegal State Exception. The path to the driver executable needs to be defined using the webdriver.gecko.driver system

Despite trying various solutions from previous related issues, I have exhausted all options but continue to encounter the same error across FireFox, Chrome, and Internet Explorer. import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; im ...

Is there a similar feature to RxJs version 4's ofArrayChanges in RxJs version 5?

Currently utilizing Angular2 and attempting to monitor changes in an array. The issue lies with only having RxJs5 available, which appears to lack this specific functionality. ...

The 'v-model' directive necessitates a valid attribute value for the left-hand side (LHS)

I am facing an issue with my Vue application. I have a table where each row has its own unique id. I need to show or hide certain elements based on a condition in the v-model directive which compares the row id with a value in the model. The current code s ...

Pause a YouTube video automatically when the window is not in focus using FancyBox

I have successfully implemented dynamic play/pause functionality for a YouTube video, as demonstrated in my weave. However, I am facing challenges in making it work dynamically with FancyBox using the onBlur event (to pause the video when the window is no ...

``What is the mechanism behind callbacks in AngularJS when making a call to a REST service?

Currently, I am diving into the world of AngularJS and REST. The code snippet that I'm analyzing has the term callback repeatedly used in an authentication function. I'm curious to know if "callback" is a JavaScript or Angular keyword, or simply ...

Showcase information from APIs using Vue.js

I am facing an issue where I am able to fetch data correctly from the API, but I am unable to display it. When I manually input items, they are displayed, but the items fetched from the API remain invisible. I even attempted to move the API call directly i ...

JQuery does not immediately update the input value

I'm working on a jQuery placeholder that mimics the behavior of default placeholders in Chrome and Firefox for browsers that don't support it. However, I'm facing an issue where the placeholder div's HTML doesn't change as quickly ...

Unable to convert JavaScript object to C# through deserialization

In order to pass a model from the controller action to the view, I included a list of objects and converted it into a JavaScript object to facilitate displaying markers on Google Maps. My goal is to send the selected object (selected marker) back to the co ...

Switch the 360-degree images by clicking a button using Panolen.js

As a beginner in the world of html, css, and javascript, I am trying to create a webpage that displays 360 panorama images. My goal is to have the image change when a button is clicked - for example, clicking on button 1 will display image1, while clicking ...

Utilizing AngularJS for Showcasing JSON Information Using Ng-Repeat and Ng-Factory

As a newcomer to Javascript and Angular, I am currently working on integrating AngularJS into my website. Despite watching tutorials from CodeSchool, Egghead, and others, I seem to be stuck at the very beginning. My issue lies in retrieving JSON data from ...

Most efficient method for nesting child objects within an array of objects using JavaScript

Hey experts, I'm on the hunt for the most efficient method to transform this data: [ { "id": 1, "animal": "cat", "age": 6, "name": "loky" }, { "id": 2, "animal": &quo ...

Transform form data into a specialized JSON structure

I have a form set up in the following way: <form id="myForm" ng-submit="submitForm()"> <select name="ItemName" ng-controller="ItemController"> <option value="" selected disabled>Select</option> <option ng-rep ...

"Interactive Connect 4 Game in Javascript - Drop the disk into the bottom row of the chosen

Check out this awesome Connect4 game I found: http://codepen.io/anon/pen/lmFJf I have a specific goal in mind for the game. When I click on an empty space in any column, I want it to automatically drop into the lowest available spot in that column, follow ...

The variable (form.onsubmit) remains unset even after assigning a value

function setFormOnSubmit(formName){ if(!formName) return; var form = document[formName]; form.onsubmit = function(){ console.log('This is the onsubmit function'); }; console.log('onsubmit successfully set ...

"Integrate a URL segment into the primary URL with the help of AngularJS or JavaScript

One interesting case involves a URL path that is structured in the following way. http://localhost:12534/urlpart1/urlpart2?querystring=140 The challenge here is to replace "urlpart2" with "urlpart3" using either javascript or AngularJS. One approach is t ...

Tips for retrieving the URL of the selected article, rather than the Google News site

When you run the code provided, it randomizes categories and selects the first article from a new site. However, after waiting for 10 seconds for the site to load using time.sleep(10), the issue arises where instead of collecting the URL of the newly loade ...