使用 RemoteWebDriver 在 Firefox 68.0 和 Safari 12.1.1 中选择 table 行时出现问题
trouble with table row selection in Firefox 68.0 and Safari 12.1.1 using RemoteWebDriver
我在使用 Firefox 和 Safari RemoteWebDrivers 时遇到 table 行 selection 问题。
table 已编码,因此单击一行 select 并双击打开表单以编辑 table 条目(如果条目是 editable)。
我需要单击 select 一行,然后按住 Shift 键单击 select table 的多个连续行。我有一个适用于 Chrome 和 Edge 但不适用于 Firefox 或 Safari 的解决方案。我真的很想要一个通用的解决方案,但我可以适应特定浏览器的特殊情况。上帝知道,我已经有很多了。 :-(
版本:
火狐:68.0
壁虎驱动程序 24.0
运行 Windows 8.1 64 位
野生动物园:12.1.1
运行 在 High Sierra 10.13.6
点击代码如下(元素是 \ 元素):
Wait.Until(d => element.Enabled);
if (Browser == BROWSERS.SAFARI)
{
IJavaScriptExecutor executor = Driver;
executor.ExecuteScript("arguments[0].focus();", element);
executor.ExecuteScript("arguments[0].click();", element);
}
else
{
element.Click(); // This only works intermittently on Safari
}
shift 点击的代码如下所示(startRow 和 endRow 是元素):
Actions action = new Actions(wd.Driver);
action.Click(startRow).KeyDown(Keys.Shift).Click(endRow).KeyUp(Keys.Shift).Perform();
Firefox 问题:
- 单击不起作用。 (见上面的代码)
预期:被点击的行是 selected。
实际:它抛出 ElementNotInteractableException。
- 按住 Shift 键并单击 select 多行就像双击一样。
我得到了我的范围的开始和结束行元素,然后执行上面显示的 shift-click 代码。
预期:startRow 和 endRow 之间的所有行都被 selected 并且没有发生其他情况。
实际:startRow 和 endRow 之间的所有行都包含 selected,但用于编辑 startRow 条目的表单也会打开。
有趣的是,它总是打开 startRow 的表单,无论我是先单击 endRow 然后再单击 startRow 还是相反。
Safari 问题:
上面显示的 Shift-click 代码导致 Safari 关闭并显示一条消息:"Safari quit unexpectedly." 报告显示:
10 com.apple.JavaScriptCore 0x000000010699b812 WTF::RunLoop::performWork(void*) + 34
11 com.apple.CoreFoundation 0x00007fff41a12581 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
12 com.apple.CoreFoundation 0x00007fff41aca8ac __CFRunLoopDoSource0 + 108
13 com.apple.CoreFoundation 0x00007fff419f5530 __CFRunLoopDoSources0 + 208
14 com.apple.CoreFoundation 0x00007fff419f49ad __CFRunLoopRun + 1293
15 com.apple.CoreFoundation 0x00007fff419f4207 CFRunLoopRunSpecific + 487
16 com.apple.HIToolbox 0x00007fff40cd4d96 RunCurrentEventLoopInMode + 286
17 com.apple.HIToolbox 0x00007fff40cd4b06 ReceiveNextEventCommon + 613
18 com.apple.HIToolbox 0x00007fff40cd4884 _BlockUntilNextEventMatchingListInModeWithFilter + 64
19 com.apple.AppKit 0x00007fff3ef84a73 _DPSNextEvent + 2085
20 com.apple.AppKit 0x00007fff3f71ae34 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
21 com.apple.Safari.framework 0x00000001059f7bf0 -[BrowserApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 273
22 com.apple.AppKit 0x00007fff3ef79885 -[NSApplication run] + 764
23 com.apple.AppKit 0x00007fff3ef48a72 NSApplicationMain + 804
24 libdyld.dylib 0x00007fff699bd015 start + 1
这对我来说不是很有用(尽管我可以认同 WTF 部分)。
我已经 "solved" shift-click 问题完全放弃行动,只使用 javascript。
public void ShiftClick(IWebElement control)
{
string shiftClickScript = "var evt = document.createEvent('MouseEvents');" +
"evt.initMouseEvent('click',true, true, window, 0, 0, 0, 0, 0, false, false, true, false, 0, null);" +
"arguments[0].dispatchEvent(evt);";
((IJavaScriptExecutor)Driver).ExecuteScript(shiftClickScript, control);
}
我仍然不知道为什么 Actions 方法不起作用...
我在使用 Firefox 和 Safari RemoteWebDrivers 时遇到 table 行 selection 问题。
table 已编码,因此单击一行 select 并双击打开表单以编辑 table 条目(如果条目是 editable)。
我需要单击 select 一行,然后按住 Shift 键单击 select table 的多个连续行。我有一个适用于 Chrome 和 Edge 但不适用于 Firefox 或 Safari 的解决方案。我真的很想要一个通用的解决方案,但我可以适应特定浏览器的特殊情况。上帝知道,我已经有很多了。 :-(
版本: 火狐:68.0 壁虎驱动程序 24.0 运行 Windows 8.1 64 位
野生动物园:12.1.1
运行 在 High Sierra 10.13.6
点击代码如下(元素是 \ 元素):
Wait.Until(d => element.Enabled);
if (Browser == BROWSERS.SAFARI)
{
IJavaScriptExecutor executor = Driver;
executor.ExecuteScript("arguments[0].focus();", element);
executor.ExecuteScript("arguments[0].click();", element);
}
else
{
element.Click(); // This only works intermittently on Safari
}
shift 点击的代码如下所示(startRow 和 endRow 是元素):
Actions action = new Actions(wd.Driver);
action.Click(startRow).KeyDown(Keys.Shift).Click(endRow).KeyUp(Keys.Shift).Perform();
Firefox 问题:
- 单击不起作用。 (见上面的代码)
预期:被点击的行是 selected。 实际:它抛出 ElementNotInteractableException。
- 按住 Shift 键并单击 select 多行就像双击一样。
我得到了我的范围的开始和结束行元素,然后执行上面显示的 shift-click 代码。
预期:startRow 和 endRow 之间的所有行都被 selected 并且没有发生其他情况。 实际:startRow 和 endRow 之间的所有行都包含 selected,但用于编辑 startRow 条目的表单也会打开。 有趣的是,它总是打开 startRow 的表单,无论我是先单击 endRow 然后再单击 startRow 还是相反。
Safari 问题: 上面显示的 Shift-click 代码导致 Safari 关闭并显示一条消息:"Safari quit unexpectedly." 报告显示:
10 com.apple.JavaScriptCore 0x000000010699b812 WTF::RunLoop::performWork(void*) + 34
11 com.apple.CoreFoundation 0x00007fff41a12581 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
12 com.apple.CoreFoundation 0x00007fff41aca8ac __CFRunLoopDoSource0 + 108
13 com.apple.CoreFoundation 0x00007fff419f5530 __CFRunLoopDoSources0 + 208
14 com.apple.CoreFoundation 0x00007fff419f49ad __CFRunLoopRun + 1293
15 com.apple.CoreFoundation 0x00007fff419f4207 CFRunLoopRunSpecific + 487
16 com.apple.HIToolbox 0x00007fff40cd4d96 RunCurrentEventLoopInMode + 286
17 com.apple.HIToolbox 0x00007fff40cd4b06 ReceiveNextEventCommon + 613
18 com.apple.HIToolbox 0x00007fff40cd4884 _BlockUntilNextEventMatchingListInModeWithFilter + 64
19 com.apple.AppKit 0x00007fff3ef84a73 _DPSNextEvent + 2085
20 com.apple.AppKit 0x00007fff3f71ae34 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
21 com.apple.Safari.framework 0x00000001059f7bf0 -[BrowserApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 273
22 com.apple.AppKit 0x00007fff3ef79885 -[NSApplication run] + 764
23 com.apple.AppKit 0x00007fff3ef48a72 NSApplicationMain + 804
24 libdyld.dylib 0x00007fff699bd015 start + 1
这对我来说不是很有用(尽管我可以认同 WTF 部分)。
我已经 "solved" shift-click 问题完全放弃行动,只使用 javascript。
public void ShiftClick(IWebElement control)
{
string shiftClickScript = "var evt = document.createEvent('MouseEvents');" +
"evt.initMouseEvent('click',true, true, window, 0, 0, 0, 0, 0, false, false, true, false, 0, null);" +
"arguments[0].dispatchEvent(evt);";
((IJavaScriptExecutor)Driver).ExecuteScript(shiftClickScript, control);
}
我仍然不知道为什么 Actions 方法不起作用...