使用selenium webdriver无法在IE中执行右键单击

时间:2018-02-09 15:49:20

标签: c# selenium webdriver

我试图右键点击IE11 selenium c#。我使用了以下两种方法,但没有一种触发右键。虽然没有收到错误,但也没有执行右键单击打开上下文菜单。 请注意我的selenium webdriver& IE Webdriver版本都是3.8。

方法1:

 string script = "var evt = document.createEvent('MouseEvents');"
                    + "var RIGHT_CLICK_BUTTON_CODE = 2;"
                    + "evt.initMouseEvent('contextmenu', true, true, window, 1, 0, 0, 0, 0, false, " +
                    " false, false, false, RIGHT_CLICK_BUTTON_CODE, null);"
                    + "arguments[0].dispatchEvent(evt);"; 
       IJavaScriptExecutor js = (IJavaScriptExecutor)SmokeTestSuite.browser;
       js.ExecuteScript(script, webElement);

方法2:

Actions builder = new Actions(SmokeTestSuite.browser);
builder.MoveToElement(objectToBeClicked);
builder.ContextClick(objectToBeClicked).Build().Perform();

HTML代码:

<div class="scrollHeader" style="overflow: hidden; padding-right: 17px;">
    <div class="tree-grid2">
        <div class="tree-grid2-row">
            <div class="tree-grid2-cell" title="Coaching Notes" style="min-width: 34px; max-width: 34px;">
                <div>
                    <div class="coaching-note-icon">&nbsp;</div>
                </div>
            </div>

InternetExplorerOptions是: EnsureCleanSession = true,IgnoreZoomLevel = true,IntroduceInstabilityByIgnoringProtectedModeSettings = true,EnableNativeEvents = false,EnablePersistentHover = false,RequireWindowFocus = true,PageLoadStrategy = PageLoadStrategy.Eager

1 个答案:

答案 0 :(得分:0)

尝试专用于您的IE版本的其他稳定版本的IE驱动程序。