2014-01-28 61 views
0

使用webdriver的用C#嘗試使用findelement

我試圖關閉使用findelement一個模式彈出來關閉模式彈出。不確定使用哪個findelement來關閉模式。

// HTML

<div id="simplemodal-container" class="simplemodal-container" style="background-color: rgb(255, 255, 255); border-color: rgb(255, 255, 255); height: 297px; padding: 0px; width: 984px; position: fixed; z-index: 1002; left: 138.5px; top: 75.5px;"> 
     <a class="modalCloseImg simplemodal-close" title="Close"></a> 
     <div class="simplemodal-wrap" tabindex="-1" style="height: 100%; outline: 0px none; width: 100%; overflow: visible;"> 
      <div id="simplemodal-data" class="simplemodal-data" style=""> 
       <div class="modal_info tariff_T010129"> 
        <img class="table_image" width="974" height="287" longdesc="http://www.three.ie/products_services/priceplans/billpay/index.html" alt="Flexifix tariff info" src="https://www.three.ie/imgs/shop/tariff_info/flexifix-tariff-table.jpg" style=""> 
       </div> 
      </div> 
     </div> 
</div> 

CSS的X按鈕

 #simplemodal-container a.modalCloseImg { 
     background: url("../Content/Images/x.png") no-repeat; top: -15px; width: 25px; height: 29px; right: -18px; display: inline; position: absolute; z-index: 3200; cursor: pointer; 
    } 

回答

0

也許最簡單的方式,因爲你已經發現了該元素的相關CSS會使用的。

driver.findElement(By.cssSelector("a.modalCloseImg")).click(); 

(這是在Java,但我敢肯定,你就可以修改C#