right click in protractor

北战南征 提交于 2020-06-08 20:08:38

问题


I'm trying to right click an element using protractor, the element is a cell in an ag-grid.

I'm trying to use some of the earlier suggestions that I could find, the only one that didn't throw me an error was the following:

browser.actions().mouseMove(elementVar).perform();
browser.actions().click(protractor.Button.RIGHT).perform();

although it doesn't right-click at all.

Any suggestions?


回答1:


From the webdriverJs api, you can right click an element thusly:

browser.actions()
    .click($('.myElm'), protractor.Button.RIGHT)
    .perform();



回答2:


Found an answer for that one. I was really close, but for the ones to look for this question the solution is this:

the elementVar you are passing to the mouseMove function, should be the desired element location. What does it mean? For example lets say we have an element called 'el' that we want to right click on it, our code needs to be like:

async function rightClick (el) {
    loc = el.getLocation();    //get the location of the element we want to click
    await browser.actions().mouseMove(loc).perform();   //takes the mouse to hover the element
    await browser.actions().click(protractor.Button.RIGHT).perform();    //performs the right click
};



回答3:


Building on @Brine's answer, I managed to work out a method without the mousemove stuff or the Jquery.

import { protractor } from 'protractor/built/ptor';

const ele = element(by.id('my_element');
browser.actions().click(ele, protractor.Button.RIGHT).perform();



回答4:


Quite sure is not a clean solution but all the script above are ok if you are using a headless chrome. If you are using a normal chrome ant the above solutions are not working, give a try at this workaround:

        await browser.actions().mouseMove(elementFinder).mouseDown().mouseMove(elementFinder).perform();


来源:https://stackoverflow.com/questions/44631069/right-click-in-protractor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!