【发布时间】:2018-05-01 04:36:29
【问题描述】:
有没有办法通过某种方式从另一个元素而不是整个驱动程序中搜索元素来执行wait.Until?
示例:
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSec));
IWebElement element = wait.Until(ExpectedConditions.ElementExists(by));
我无法将'by' 修改得过于具体,并且当在驱动程序下搜索它并获取错误的元素时。
IWebElement element = wait.Until(drv => drv.FindElement(by));
此选项还在driver 下搜索。
我想要这样的东西:
public static IWebElement WaitElement(this IWebElement webElement, IWebDriver driver, By by, int timeoutInSec = 5)
{
try
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSec));
IWebElement element = wait.Until(webElement.FindElement(by));
}
当我尝试编写此代码时,我收到此错误:
【问题讨论】:
-
您所做的实际上是正确的。您可以从专利元素中找到子元素。
-
我写的(最后一个代码)不“合法”,不被接受
-
使用 By.CssSelector("#parentId #childId");
-
达芙妮,你有没有找到解决办法?我遇到了同样的问题,我在循环找到的元素并且需要等待每个元素的子元素。