标签:selenium selenium-webdriver c
C#,Winform,Selenium Firefox网络驱动程序.
基本上我需要等到某个元素等于程序中的某个值,这就是我尝试过的
public static string Watchprogress;
Watchprogress = driver.FindElement(By.XPath("//*[@id='watch-toolbar']/aside/div/span")).Text.ToString();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(90)).Until(Watchprogress == "3");
//And this
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(90)).Until(By.XPath("//*[@id='watch-toolbar']/aside/div/span")).Text.ToString() == "3");
得到这个错误
无法从用法中推断出方法’OpenQA.Selenium.Support.UI.DefaultWait.Until(System.Func)’的类型参数.尝试显式指定类型参数. 5079
硒仍然有点新,所以我一直在尝试和尝试.
解决方法:
这里有几件事.在这里,直到()的实现是错误的.您必须在这里使用ExpectedConditions或编写自定义函数(请参见下面的内容).请参见api
By byXpath = By.XPath("//*[@id='watch-toolbar']/aside/div/span");
IWebElement element =
new WebDriverWait(_driver, TimeSpan.FromSeconds(90)).Until(ExpectedConditions.ElementExists(byXpath));
if (element.Text.Trim() == "3")
{
//Pass this
}
LINQ的另一种选择
string watchprogress = new WebDriverWait(_driver, new TimeSpan(10)).Until(e => e.FindElement(byXpath)).Text.Trim();
if (watchprogress == "3")
{
}
要么
简单地说,如果您要等到元素获得文本3,则使用bool指示器
bool watchprogress =
new WebDriverWait(_driver, new TimeSpan(10)).Until(e => e.FindElement(byXpath)).Text.Trim().Equals("3");
要么
IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));
wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
//First wait for the page to be completely loaded.
WebDriverWait wait2 = new WebDriverWait(driver, TimeSpan.FromSeconds(90));
wait2.IgnoreExceptionTypes(typeof(StaleElementReferenceException));
wait2.Until(d => d.FindElement(By.XPath("//*[@id='watch-toolbar']/aside/div/span")).Text.Contains("3"));
标签:selenium,selenium-webdriver,c 来源: https://codeday.me/bug/20191120/2045957.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。