如何使用WebDriverWait从另一个元素selenium获取元素?

时间:2017-05-17 05:15:24

标签: c# selenium selenium-webdriver webdriver

请看这个:

IWebDriver driver;
WebDriverWait WebDriverWait;

public IWebElement Button
{
    return new WebDriverWait(driver, TimeSpan.FromSeconds(60)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("bla bla")));
}

现在,如果我想搜索一些IWebElement,而不是driver.FindElement,我想使用另一个IWebElement我可以执行以下操作:

IWebElement webElement..
IWebElement webElement e = webElement.FindElement(By.XPath("my selector"));

因此,在这种情况下,我想使用WebDriverWait代替webElement.FindElement

有可能吗?

1 个答案:

答案 0 :(得分:2)

WebDriverWait.Until()返回IWebElement,您可以将返回的值分配给变量或只是连接另一个方法

IWebElement element = new WebDriverWait(driver, TimeSpan.FromSeconds(60)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("bla bla")));
element.FindElement((By.XPath("my selector"));

相同
new WebDriverWait(driver, TimeSpan.FromSeconds(60)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("bla bla"))).FindElement(By.XPath("my selector"));