C# Selenium:ExpectedConditions.UrlContains-可能的错误?
我正在使用名为C# Selenium:ExpectedConditions.UrlContains-可能的错误?,c#,selenium,C#,Selenium,我正在使用名为ExpectedConditions.UrlContains的内置函数。此函数接受一个参数,即字符串。在某些情况下,即使URL正确,条件也会失败。这可能是一只虫子吗 代码本身非常简单: public static class SeleniumExtensionMethods { public static WebDriverWait wait = new WebDriverWait(SeleniumInfo.Driver, TimeSpan.FromSeconds(20));
ExpectedConditions.UrlContains
的内置函数。此函数接受一个参数,即字符串
。在某些情况下,即使URL正确,条件也会失败。这可能是一只虫子吗
代码本身非常简单:
public static class SeleniumExtensionMethods
{
public static WebDriverWait wait = new WebDriverWait(SeleniumInfo.Driver, TimeSpan.FromSeconds(20));
public static void WaitUntilUrlContains(this IWebDriver driver, String value)
{
try
{
wait.Until(ExpectedConditions.UrlContains(value));
}
catch (TargetInvocationException ex)
{
Console.WriteLine(ex.InnerException);
}
}
}
class HomePage : Page
{
public void Login()
{
//Here is some code to log in ...
//Here a redirect to a different page occurs ...
String browserTitle = SeleniumInfo.Driver.Title; // returns "Index"
SeleniumInfo.Driver.WaitUntilUrlContains("Index"); // returns the exception
}
}
异常消息:
向发送HTTP请求时引发了具有空响应的异常
URL的远程WebDriver服务器
.
异常状态为ConnectFailure,消息为:
无法连接到远程服务器
最后一点,在我的代码中的任何其他方法中,这个异常似乎从未发生过,除了这个偶尔发生的方法
为什么会发生这种情况?怎么能修好呢?是否有解决方法?尝试将驱动程序的超时设置为更长的时间,或者尝试使用不同的浏览器/驱动程序。a)超时设置为20秒,这足够长了。在这段时间之后,页面肯定会被加载,JavaScript也会被加载。我可以亲眼看到页面已加载,Url包含“索引”,但它仍然会给出一个异常,因此不能将超时设置得更大,抱歉。另外,我只使用ChromeDriver。可能是区分大小写的问题?实际URL包含“索引”,但您正在等待“索引”。您找到了这个问题的根本原因吗?我不记得了(这是2年前的lol)。你也有同样的问题吗?