2016-12-14 67 views
0

我正在尋找驗證鏈接被禁用的方法。這是一個子菜單鏈接,我將鼠標懸停在home menu鏈接上,然後顯示子菜單鏈接列表。由於某些用戶角色,此用戶無法訪問報告頁面,因此我需要驗證該鏈接已禁用。 class屬性表明。紅寶石黃瓜:使用頁面對象獲取屬性

HTML:

<div id="homeMenu"> 
    <ul> 
     <li class="has-sub"> 
      <a class="homeButton" href="/report-web"></a> 
      <ul id="homeLinks"> 
      <li id="oepLiId"> 
        <a id="reportLinkId" class="disabledLinks" href="/report-web/openItems?subApp=OEP&rptid=15"> 
        <span id="reportLinkName">Reporting Processing</span> 
       </a> 
      </li> 
     </ul> 
     </li> 
     </ul> 
    </div> 

我使用看跌期權如下:

link = @browser.find_element(:id, 'reportLinkId') 
    puts link.displayed? 
    puts link.enabled? 

它打印:

true 
    true 

的聯繫是displayedenabled。我能想到的唯一方法是檢查class屬性以查看它是否被定義爲disabledLinks

使用頁面對象:

 link(:report_link, :id => 'reportLinkId') 


     class_attribute = report_link_element.attribute('class') 
     expect(class_attribute.eql?('disabledLinks')).to be true 

不使用頁面對象:

 class_attribute = @browser.find_element(:id, 'reportLinkId').attribute('class') 

但是,這兩種方式,我得到了class_attribute是空的。

環境:

Ruby: 1.9.3 
    Cucumber: 2.1.0 
    Selenium Webdriver: 2.53.4 
    page-object: 1.2.0 

我缺少什麼?

+0

在你的HTML例子中,你有一個'id =「oepLinkId」'的鏈接,但是在你的頁面對象中使用':id =>'reportLinkId'' – Evmorov

+0

@Evmorov好的。這是一個錯字。我更新了我的問題。問題依然存在。謝謝! – fongfong

+0

你的代碼在簡單的頁面上可以正常工作。您是否在只有該鏈接的頁面上嘗試過您的代碼?你使用什麼瀏覽器(我試過Chrome和IE11)。我使用Ruby 2.3,但似乎不太可能成爲問題。 –

回答

0

這是發生了什麼事。 id值在開發過程中發生了變化。我更新了它,它工作。謝謝大家!