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



请看这个:

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

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

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

所以在这种情况下,我想使用 WebDriverWait 而不是只是 webElement.FindElement .

可能吗?

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"));

最新更新