Selenium WebriverJS does not support right mouse button clicks in PhantomJS

Currently, I am utilizing Selenium in combination with WebdriverJS to automate a straightforward web application. However, an issue arises when transitioning from Chrome to PhantomJS, resulting in the test not functioning as intended. Specifically, the right mouse button fails to trigger the context menu. Has anyone encountered a similar problem before, and if so, what solutions were implemented? Below is a snippet of the code in question:

 return driver.actions()
        .mouseMove(driver.findElement(mapping.xpath.spaceSpace), {x:120, y:120})
        .click(mapping.key.mouseRightButton)
        .perform()

I have attempted various approaches such as removing coordinates, incorporating them within the click action, and experimenting with different mouse events - yet nothing has proven successful. It's worth noting that the same tests execute flawlessly in Chrome, Firefox, and IE.

Answer №1

This issue has been resolved but has not yet been released. Visit https://github.com/ariya/phantomjs/issues/14005 for more information.

While waiting for the fix, here are some alternative solutions:

Java

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.phantomjs.PhantomJSDriver;

public void contextClick(WebDriver driver, WebElement element) {
    if(driver instanceof PhantomJSDriver) {
        String script =
                "var element = arguments[0];" +
                "var event = document.createEvent('HTMLEvents');" +
                "event.initEvent('contextmenu', true, false);" +
                "element.dispatchEvent(event);";
        ((JavascriptExecutor)driver).executeScript(script, new Object[]{element});
    } else {
        (new Actions(driver))
                .contextClick(element)
                .build()
                .perform();
    }
}

Python

from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver import PhantomJS, ActionChains

def context_click(driver, element):
    # type: (WebDriver, WebElement) -> ()
    if isinstance(driver, PhantomJS):
        script = "var element = arguments[0];" \
                "var event = document.createEvent('HTMLEvents');" \
                "event.initEvent('contextmenu', true, false);" \
                "element.dispatchEvent(event);"
        driver.execute_script(script, element)
    else:
        ActionChains(driver) \
            .move_to_element(element) \
            .context_click() \
            .perform()

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

Following a series of Observables in Angular 2+ in a sequential order

Apologies if this question has been answered elsewhere, I attempted to search for it but I'm not exactly sure what I should be looking for. Imagine I have this complex object: userRequest: { id: number, subject: string, ... orderIds: ...

Come hang out in the user voice channel by reacting with your favorite emojis!

I am currently developing a Discord bot, and I want to implement a feature where the bot joins a voice channel if a user reacts to its message. I am using the awaitReactions function which only returns reaction and user data. Is there a way to retrieve th ...

Detecting collisions on a pixel-by-pixel basis within Javascript/Jquery/Gamequery

Currently, I am working on developing a web game using Jquery with the GameQuery plugin. However, I have encountered an issue where the GameQuery plugin does not support per pixel collision detection, only bounding boxes collision detection. Is there a way ...

Strategies for reversing strings in JavaScript without relying on built-in functions

Are you wondering how to reverse the words in a string without using the split, reverse, and join functions? Here is the problem: You need to reverse the words in a string. For example, if the input is "Hello World," the output should be "World Hello." ...

Error message stating: "Node.js 'readline' - Mark-compacts near heap limit are not effective. Allocation failed."

Here's the process I'm following in the code: Primarily, I am engaging in web scraping tasks. I start by reading a text file containing approximately 3500 links. Next, I iterate through each link, filter out the ones I need, and make a request ...

Exploring the capabilities of zooming on SVG elements using D3 within an Angular

I want to implement pan/zoom functionality on an SVG element. I came across a tutorial that suggested using d3.js for this purpose, you can find it here Below is the code I have tried: import { Component,AfterViewInit,OnInit } from '@angular/core&a ...

Insert information into a nested array using Mongoose

I'm encountering an issue with my code, even though I know it may be a duplicate. Here is the snippet causing me trouble: exports.addTechnologyPost = function(req, res){ console.log(req.params.name); var query = { name: 'test ...

View / Conceal Unordered List depending on link selected

How can I dynamically show or hide UL elements based on the clicked link? Here is a JS Fiddle example: http://jsfiddle.net/zangief007/rj8g0yh4/1/ Below is the HTML code: <ul class="category-1 group"> <li class="name">JOHN Smithe QC</l ...

Can passing parameters between nested map functions cause any issues?

While attempting to navigate to a page in reactjs and pass parameters using the useNavigate hook, I encounter an unexpected token error as soon as I include the navigation within the anchor tag. <a onClick={() ={ ...

Transferring data between two "Data" elements using Jquery Datatable

Utilizing the JQuery datatable, I have made the first column of my table clickable, which is labeled as RequestNo. Here's the code snippet: "ajax": { "url": "/Request/Search/LoadData", "type": "POST", "datatype": "j ...

Can you explain the BDD feature file structure for transferring to TestRail?

Having trouble importing BDD feature files from my Automation Framework into TestRail. Even after using the 'Import .feature files into TestRail' feature, the file imports without any testcases and I'm unable to manually add them. Trying to ...

What could be causing my search function to not recognize special characters?

It seems like there might be an issue with character encoding. My JavaScript search function is unable to identify specific strings that contain certain special characters such as parentheses, asterisks, and numbers. The JavaScript code I am using is quit ...

Error: The specified method org.apache.http.conn.scheme.Scheme.<init>() does not exist

Having trouble while running a selenium test in a Maven project? This project is a GWT Web application with GWT and Hibernate dependencies listed in the pom.xml file. I have created a new test class in the test package to run the selenium test case. Even a ...

What is the best way to add a URL dynamically when a click event occurs?

Here is the code where I am making an API call: export const filteredProducts = (e) => { const radio = e.target.checked; return dispatch => { dispatch({type: actionTypes.TOGGLE_LOAD}); axios.get(radio ? `/store?limit=9&skip=0&subc ...

Having trouble selecting a default option in a dynamically populated select dropdown using ng-model in the dropdown

For my Angularjs application, I needed to dynamically return a select drop down with its selected option. To accomplish this, I implemented the following function: function getCellRendererMapping(data) { if (data.order == 6) { return funct ...

Selenium throws an exception indicating that the element was not found when attempting to locate it in a new tab

Scenario: A user clicks on a link or button which opens a new tab and redirects them to it. Issue: I am facing difficulty performing actions on the new tab using Selenium WebDriver in Java. Whenever I try to interact with elements, an exception is thr ...

Transitioning the Background Image is a common design technique

After spending hours trying to figure out how to make my background "jumbotron" change images smoothly with a transition, I am still stuck. I have tried both internal scripts and JavaScript, but nothing seems to work. Is there any way to achieve this witho ...

What is the best way to retrieve information from a function that returns an AJAX GET JSON response?

There is a function in my code that uses ajax to return JSON data: function fetchTagData(fileName) { $.ajax({ type: "GET", dataType: "json", url: "/tags/find-tag/"+fileName.tag, success: function(data){ con ...

How to import a module from the root path using TypeScript in IntelliJ IDEA

Despite this topic being widely discussed, I still struggle to understand it. Below is my tsconfig.json file: { "compilerOptions": { "module": "commonjs", "target": "es2017", "sourceMap": true, "declaration": true, "allowSyntheticDe ...

Setting the default type of an array in props in Vue 2 is a common need for many developers

My Vue component relies on an array of objects as a prop and I always make use of prop validation, especially for setting default values. In this case, my current setup is: props: { items: Array } However, I would prefer it to resemble something lik ...