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

标签 c# selenium webdriver

我正在尝试对 IE11 selenium c# 执行右键单击。我正在使用以下两种方法,但它们都不会触发右键单击。虽然没有收到错误,但也没有执行右键单击以打开上下文菜单。
请注意我的 selenium webdriver 和 IE Webdriver 版本都是 3.8。

方法一:

 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);

方法二:
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

最佳答案

尝试不同的稳定版本的 IE 驱动程序,该版本专用于您的 IE 版本。

关于c# - 无法使用 selenium webdriver 在 IE 中执行右键单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48709464/

相关文章:

c# - 更新 WPF 桌面桥通用应用程序时无法升级设置

c# - Pig Latin 控制台

c# - 将对角线延长一个值

java - 我如何处理允许使用带有 Java 的 Selenium Webdriver 的 firefox 插件的弹出窗口

python - 网站检测到 selenium webdriver

c# - 如何重复失败的测试,以便它仅在 x 次重复后失败?

c# - 有没有办法让 .Net JIT 或 C# 编译器优化掉空的 for 循环?

使用 selenium2+phpunit 选择一个选项

webdriver - keep-order 设置 true 不会按照定义的组依赖关系的顺序运行 TestNG 测试

python - 我正在尝试为添加按钮制定 Xpath 或 CSS