Ajax中的元素弹出(按钮)在selenium中无法找到?

时间:2014-12-21 11:13:25

标签: selenium selenium-webdriver getelementbyid

我需要在selenium webdriver.THis元素中选择弹出窗口内的元素作为ajax popup pleae帮助我吗?

<a class="modalCloseImg simplemodal-close" title="Close"></a>
<div class="simplemodal-wrap" tabindex="-1" style="height: 100%; outline: 0px none; width: 100%; overflow: auto;">
    <div id="ajaxcart" class="ajaxcart simplemodal-data" style="">
        <p class="popup-success-msg"></p>
        <div class="popup-content"></div>
        <div class="ajaxcart-buttons-container">
            <a class="simplemodal-close btn-small-dark-grey"></a>
            <a class="ajaxcart-btn btn-small-orange" href="http://www.xcite.com"></a>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:-1)

尝试使用以下代码等待10秒钟让元素可见,然后点击元素

try{
    WebDriverWait wait = new WebDriverWait(driver, 10);
    WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='ajaxcart']//a[starts-with(@class,'ajaxcart-btn')]")));
    element.click();
    System.out.println("Clicked on the element successfully");
}catch(Throwable e){
    System.err.println("Error came while waiting for the element and clicking on it. "+e.getMessage());
}