Emulate clicking a link with Javascript that works with IE

后端 未结 5 910
别那么骄傲
别那么骄傲 2020-12-02 20:40

I want to have java script clicking a link on the page..I found something on the net that suggests adding a function like this:

function fireEvent(obj,evt){
         


        
5条回答
  •  既然无缘
    2020-12-02 21:35

    We found a simpler way to simulate right click (tested in IE8). Use a double click or two single clicks, then right-click using Shift-F10. I don't know exactly why this works, but it does. In the sample code below, we use the Selenium method to click twice, then use the IE Driver to find the WebElement and send the key sequence Shift-F10, which emulates the right-mouse button click. We use this to testing GWT based web apps. One place this did not work as well was in a tree control where the context menu was set to appear at the mouse's coordinates. Often, the mouse coordinates were negative, so right-clicking the menu item did not cause the child menu options to get displayed. To handle this case, we added a bit of code to the control so that if the mouse coordinates were negative, the context menu appears at a 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);
    

提交回复
热议问题