我正在尝试对 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"> </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/