We found an easier way to simulate a right click (tested in IE8). Use a double click or two clicks, then right-click using Shift-F10. I don’t know exactly why this works, but it is. In the following code example, we use the Selenium method to double-click, then use the IE driver to find WebElement and send the Shift-F10 key sequence that emulates a right-click. We use this to test GWT-based web applications. In one place, this did not work, it was in the control tree, where the context menu was set to appear in the coordinates of the mouse. Often the coordinates of the mouse were negative, so right-clicking on a menu item did not display the parameters of the child menu. To handle this case, we added some code to the control, so that if the mouse coordinates were negative, the context menu is displayed at 0.0.
selenium.click("//td[@role='menuitem' and contains(text(), 'Add')]"); selenium.click("//td[@role='menuitem' and contains(text(), 'Add')]"); new InternetExplorerDriver().findElement(By.xpath("//td[@role='menuitem' and contains(text(), 'Add')]")).sendKeys(Keys.SHIFT, Keys.F10);
Rich Jun 15 2018-10-15T00: 00Z
source share