1

I'm developping a basic firefox addon and I would like to test if a certain item is present in a context menu (displayed after a right click anywhere on the page).

I've seen that I could use marionette and selenium-webdriver but I can't find a way to click anywhere on the page and assert that a given item is present in the context menu.

I have a hard time simply right-clicking (not even talking about checking if the item is in the context menu...).

According to the documentation on ActionSequence I should use click and provide a right button click. I couldn't get it to work though. Here is what I've tried so far

const webdriver = require('selenium-webdriver');
const Capabilities = require('selenium-webdriver/lib/capabilities').Capabilities;
const input = require('selenium-webdriver/lib/input');

var capabilities = Capabilities.firefox();

capabilities.set('marionette', true);

var driver = new webdriver.Builder().withCapabilities(capabilities).build();

driver.get('http://localhost');

// Using a element for opt_elementOrButton
driver.actions().click(driver.findElement(webdriver.By.css('#changes')), input.Button.RIGHT).perform();

// Using right buttons
//driver.actions().click(input.Button.RIGHT, input.Button.RIGHT).perform();

// Using only one argument, as the second argument opt_button is "Ignored if a button is provided as the first argument"
//driver.actions().click(input.Button.RIGHT).perform();

//driver.quit();
user7890
  • 147
  • 2
  • 11

1 Answers1

0

You can perform a right-click by using Actions.contextClick() but you will not be able to access the context menu to verify that an option is present, etc. Sample code to perform the right-click is below.

WebElement e = driver.findElement(locator);
Actions action = new Actions(driver);
action.contextClick(e).build().perform();

Reference https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/interactions/Actions.html#contextClick--

JeffC
  • 22,180
  • 5
  • 32
  • 55
  • Thank you, but I'm using `node` and it looks like the right click (this method `driver.actions().click(input.Button.RIGHT).perform();`) is not working with `firefox` (investigating with `chrome` works perfectly)... Any idea what could be going wrong? – user7890 Aug 09 '16 at 15:32