为什么 Selenium ExecuteScript 方法在 Salesforce 应用程序中不再起作用但 ExecuteAsyncScript 起作用

Why does Selenium ExecuteScript method doesn't work anymore in Salesforce application but ExecuteAsyncScript works

嗨,过去几天我一直在努力解决这个问题。我在下面编写了用于工作但不再使用 ExecuteScript 方法工作的代码。我唯一改变的是更新我的 chrome 驱动程序,因为它没有启动 chrome 因为驱动程序不能与我拥有的旧 chrome 版本一起使用。因此,一旦我更新了 chrome 驱动程序,它就开始工作,直到我不得不 运行 这段代码。我在下面将其修改为实际的 link 文本。

            IJavaScriptExecutor js = (IJavaScriptExecutor)WebActions.One;
            js.ExecuteScript("alert('Welcome to Guru99');"); // This was added for testing purpose
            IWebElement somelink = WebActions.One.FindElement(By.XPath("//span[text()='Some Text']"));
            js.ExecuteScript("arguments[0].click();", somelink );

当我将方法更改为 ExecuteAsyncScript 时,它又开始工作了。这是应用程序发生了变化还是我做错了什么。我尝试阅读 ExecuteAsyncScript 与 ExecuteScript 以了解不同之处,但我所能得到的只是关于回调的一些信息 当它完成时,我在 java 脚本中没有经验。

我只想了解更多,或者我应该开始使用 ExecuteAsyncScript 方法。谢谢

此处有关于此问题的 chromedriver 票证:

https://bugs.chromium.org/p/chromedriver/issues/detail?id=3103

它指出:

The cause of the issue is this website modifies the constructor of the built-in AsyncFunction object. This causes difficulty when ChromeDriver tries to create an AsyncFunction to wrap the script being executed.

chromedriver 78 修复了这个问题。为了使用 Chrome 77 进行测试,票证建议切换到 executeAsyncScript,或者使用 chromedriver 76,因为 "ChromeDriver vX will run with Chrome vX+1".