[英]Selenium and Internet Explorer Driver
I'm trying to run some tests with C# and InternetExplorerDriver. 我正在尝试使用C#和InternetExplorerDriver运行一些测试。
This code is executed on Windows Server 2012, 64 bit. 此代码在Windows Server 2012 64位上执行。
Right after navigation to a new URL, I'm calling a function that waits until a page loads\\20 seconds timeout. 导航到新URL之后,我正在调用一个函数,该函数等待页面加载\\ 20秒超时。
private bool waitForPageToLoad()
{
try
{
int timeout = int.Parse(ConfigurationManager.AppSettings["TimeoutForCustomExpression"]);
IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(m_driver, TimeSpan.FromSeconds(timeout));
wait.Until(driver1 => ((IJavaScriptExecutor)m_driver).ExecuteScript("return document.readyState").Equals("complete"));
}
catch//(Exception e) //timeout
{
log(e.Message + e.StackTrace);
return false;
}
return true;
}
The function works great for every browser other than IE. 该功能适用于除IE之外的所有浏览器。
On IE, I the following error in my log: 在IE上,我在日志中出现以下错误:
JavaScript error (UnexpectedJavaScriptError) at OpenQA.Selenium.Support.UI.DefaultWait
1.PropagateExceptionIfNotIgnored(Exception e) in c:\\Projects\\WebDriver\\trunk\\dotnet\\src\\WebDriver.Support\\UI\\DefaultWait.cs:line 222 at OpenQA.Selenium.Support.UI.DefaultWait
1.Until[TResult](Func`2 condition) in c:\\Projects\\WebDriver\\trunk\\dotnet\\src\\WebDriver.Support\\UI\\DefaultWait.cs:line 180 at MainClass.waitForPageToLoad()OpenQA.Selenium.Support.UI.DefaultWait上的JavaScript错误(UnexpectedJavaScriptError)1
1.PropagateExceptionIfNotIgnored(Exception e) in c:\\Projects\\WebDriver\\trunk\\dotnet\\src\\WebDriver.Support\\UI\\DefaultWait.cs:line 222 at OpenQA.Selenium.Support.UI.DefaultWait
1.1.PropagateExceptionIfNotIgnored(Exception e) in c:\\Projects\\WebDriver\\trunk\\dotnet\\src\\WebDriver.Support\\UI\\DefaultWait.cs:line 222 at OpenQA.Selenium.Support.UI.DefaultWait
MainClass.waitForPageToLoad的c:\\ Projects \\ WebDriver \\ trunk \\ dotnet \\ src \\ WebDriver.Support \\ UI \\ DefaultWait.cs:line 180中的[TResult](Func`2条件) ()
I have no idea why it happens. 我不知道为什么会这样。 Could somebody help me out here?
有人可以帮我吗?
Sincerely, Adam. 真诚的亚当。
Without seeing all that extra information that Arran requested, it's hard to help you understand the error. 没有看到Arran要求的所有其他信息,很难帮助您理解该错误。 However if you're just looking for a quick fix that works in all browsers, I always just use
Thread.sleep(int milliseconds);
但是,如果您只是想寻找一种适用于所有浏览器的快速修复程序,我总是只使用
Thread.sleep(int milliseconds);
for my Selenium tests in C# that need to wait for a page to load or a certain element to render before continuing. 对于我在C#中进行的Selenium测试,需要等待页面加载或某个元素呈现后才能继续。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.