我使用的是Selenium ChromeDriver v2.9.248315。当我单击导致页面回发的按钮时,我无法再执行browser.ExecuteScript而不会出错。此外,如果我尝试browser.Refresh(),我收到相同的错误。我完全不知道如何继续。我试图从现有的浏览器标题加载新的BrowserWindow。我尝试刷新BrowserWindow进程。任何帮助将不胜感激/
BrowserWindow.CurrentBrowser = "chrome"
browser = BrowserWindow.Launch(websiteUrl);
string script = "console.log('test');";
// Works
browser.ExecuteScript(script)
browser.Click<HtmlInputButton>("SaveChanges", PropertyExpressionOperator.Contains);
// Click causes Postback, Script no longer works and throws the error
browser.ExecuteScript(script)
同样转载:
BrowserWindow.CurrentBrowser = "chrome"
browser = BrowserWindow.Launch(websiteUrl);
browser.Refresh();
string script = "console.log('test');";
browser.ExecuteScript(script)
Repro的另一种方法:
BrowserWindow.CurrentBrowser = "chrome"
browser = BrowserWindow.Launch(websiteUrl);
// Refresh / Hard Refresh
string script = "console.log('test');";
browser.ExecuteScript(script)
但这有效:
BrowserWindow.CurrentBrowser = "chrome"
browser = BrowserWindow.Launch(websiteUrl);
// Empty Cache and Hard Reload (Ctrl + F5)
string script = "console.log('test');";
browser.ExecuteScript(script)
日志失败:
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestJScriptExecutionException was unhandled by user code
BasicMessage=Could not load type 'OpenQA.Selenium.IllegalLocatorException' from assembly 'WebDriver, Version=2.53.0.0, Culture=neutral, PublicKeyToken=1c2bd1631853048f'.
HResult (System.Exception)=-2146233088
HResult=-2146233088
Message=Could not load type 'OpenQA.Selenium.IllegalLocatorException' from assembly 'WebDriver, Version=2.53.0.0, Culture=neutral, PublicKeyToken=1c2bd1631853048f'.
Source=Microsoft.VisualStudio.TestTools.UITest.Extension.CrossBrowser
StackTrace:
at Microsoft.VisualStudio.TestTools.UITest.Extension.CrossBrowser.CrossBrowserService.ExecuteScript(String script, Object[] args)
at Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow.<>c__DisplayClass24_0.<ExecuteScript>b__0()
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
at Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow.ExecuteScript(String script, Object[] args)