无法单击动态创建的div

时间:2015-07-10 07:10:08

标签: java c# jquery xpath selenium-webdriver

使用此Java代码,我能够找到该元素并单击

Wait wait = new FluentWait(driver).withTimeout(30, TimeUnit.SECONDS)
            .pollingEvery(1, TimeUnit.SECONDS)
            .ignoring(StaleElementReferenceException.class);

    wait.until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver driver) {
            return driver.findElement(locator).isDisplayed();
        }
    });
    driver.findElement(locator).click();

但是当我尝试在c#中写相同内容时,我无法找到并点击div

相同的C#代码

public static void selectUsingAutoComplete(IWebDriver driver,String locator)
{
    WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
    wait.IgnoreExceptionTypes(typeof(StaleElementReferenceException)); 
    wait.Until(ExpectedConditions.ElementToBeClickable(driver.FindElement(By.XPath(x‌​path here))));
    wait.PollingInterval = TimeSpan.FromSeconds(2); wait.Until(d => d.FindElement(By.XPath(".//*[@class='list']")).Displayed);
    driver.FindElement(By.XPath(".//*[@class='list']")).Click();
}

0 个答案:

没有答案