【问题标题】:Right click could not be performed in IE using selenium webdriver使用 selenium webdriver 无法在 IE 中执行右键单击
【发布时间】:2018-07-20 10:31:14
【问题描述】:

我正在尝试在 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);

方法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. //div[@class='scrollHeader'] 2. //div[@class='tree-grid2'] 甚至 3. //div[@标题='教练笔记']。他们都没有工作。请注意,成功找到了 Element,但没有执行该右键单击事件
  • 它在其他浏览器中是否有效?
  • 是的,它使用 Selenium 的 Actions 类代码在 Chrome 中工作。

标签: c# selenium webdriver


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2012-07-20
    • 1970-01-01
    • 1970-01-01
    • 2012-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-17
    相关资源
    最近更新 更多