2014-12-21 34 views
1

我需要選擇selenium webdriver.This中的彈出窗口中的元素作爲ajax popup pleae幫助我嗎?Ajax中的元素在seleinum中彈出(按鈕)無法找到?

<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

哪個元素你在說什麼? ''或'' – Subh

+0

這個元素,這是在ajax彈出框裏面。 – Flintoff

回答

0

嘗試下面的代碼,等待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()); 
}