MoveToElement - RemoteWebDriver 引发了 'System.InvalidOperationException' 类型的异常

MoveToElement - RemoteWebDriver threw an exception of type 'System.InvalidOperationException'

我正在使用下面的代码移动到元素,但 actionExecutor returns 是一个例外。

IWebElement element = driver.FindElement(By.LinkText(link_text));
Actions ac = new Actions(driver);
ac.MoveToElement(element);
ac.Build().Perform();

我收到评论说“这不是 w3c 的有效端点,Chrome 不再支持它。” https://github.com/SeleniumHQ/selenium/issues/10344

关于如何解决 MoveToElement 方法的问题,请问有什么建议吗?

在移动到元素之前,您必须检查是否确实找到了它:

IWebElement element = driver.FindElement(By.
LinkText(link_text));
if (element!=null) {
   Actions ac = new Actions(driver);
   ac.MoveToElement(element);
   ac.Perform();
}

请注意,您可以删除 Build() 调用,因为您只执行一个操作,而不是更多。

如果您找到的元素确实为 null,请尝试通过 XpathCSS 而不是通过 LinkText 找到它。