2012-10-11 39 views
1

我正在使用供應商開發的網頁(SAP BusinessObjects InfoView登錄頁面),並嘗試識別並選擇頁面上的下拉元素。不管我怎麼努力,我得到一個異常:使用動態幀查找HTML頁面中的元素

require 'watir-webdriver' 
ie = Watir::Browser.new 
ie.goto "http://svr-boj-bop-01.mgc.mentorg.com:8080/InfoViewApp" 
ie.select_list(:id, "authenticationSelectBox").select("secLDAP") 
#=> 'error: "unable to locate element, using :id=>"authenticationSelectBox", :tag_name=>"select"....' 

我已經安裝了Firefox和Firebug的,我可以用Firebug的選擇,給了我關於元素的信息元素。我試圖指定:id,:name,.div,.browser,.frame,...沒有任何更改錯誤。我懷疑內部框架是基於選擇「認證」動態地創建頁面,但我不知道如何檢查/驗證是這種情況。

我已經搜索並嘗試了網站上的大部分建議,沒有任何幫助。

頁有很多的Java代碼,表格等下面是從頁剪斷我試圖尋找元素:

<body onload="logonPageLoad()"> 
    <div class="logonContainer"> 
     <div class="logonIFrame"> 
      <iframe id="infoView_home" width="80%" frameborder="0" align="center" title="Log On to InfoView" name="infoView_home" onload="resizeFrameToContent("infoView_home")" src="jsp/listing/blank.jsp" style="height: 287px;"> 
       <html class="logon_body"> 
        <body class="logon_body" onload="loadInit();"> 
         <div class="logon_body"> 
          <div id="logonCredentials"> 
           <form action="../../../PartnerPlatformService/service/app/logon.object" method="POST" name="logonForm"> 
            <div class="logon_table"> 
             <div id="authentication" class="logon_input"> 
              <label class="logon_input_label" onclick="businessobjects.webutil.accessibility.setFocusOnElement('authenticationSelectBox'); return false;" tabindex="-1" for="authenticationSelectBox"> Authentication: < /label> 
              <select id="authenticationSelectBox" class="logonSelectBox" onchange="SetAuthType(false);resizeFrameToContent('infoView_home')" name="authType"> 
               <option value="secEnterprise" selected=""> Enterprise `</option> 
               <option value="secLDAP"> LDAP </option> 
               <option value="secWinAD"> Windows AD </option> 
               <option value="secSAPR3"> SAP</option> 
              </select> 
+0

抱歉所有的編輯/轉貼。感謝賈斯汀柯指針。我已經添加了從頁面完整的HTML,希望它可以幫助 –

回答

2

對於幀的元素,你必須明確地叫喚框架:

my_frame = ie.frame(:id, "infoView_home") 
my_frame.select_list(:id, "authenticationSelectBox").select("secLDAP") 

儘管聽起來像你可能已經嘗試過。 Watir認爲該頁面已加載之前,該元素可能未被加載。如果是這種情況,可以使用類似when_present方法的方法添加等待。

my_frame = ie.frame(:id, "infoView_home") 
my_frame.select_list(:id, "authenticationSelectBox").when_present.select("secLDAP") 

注意,你可以做到這一點的一條線(即你不需要my_frame)。它只是爲了更容易閱讀(即最小化水平滾動)而添加的。

+0

感謝賈斯汀柯,那是票... –

+0

也,我得到了一個額外的錯誤進一步下來在我的腳本,這一個有關登錄領域。我現在從這個腳本片斷中得到下面的錯誤:my_frame.text_field(:name,「password」)。set「dsopen」.error = [remote server] resource://fxdriver/modules/web_element_cache.js:5671 :在'未知':元素屬於一個不同的框架,而不是古銅色一個 - 切換到它的包含框架使用它(Selenium :: WebDriver :: Error :: StaleElementReferenceError) 我沒有看到另一個框架引用..我應該試圖找到另一種類型的標籤嗎? –

+0

根據您的頁面的HTML,沒有名稱爲「password」的文本字段。只有在更改選擇列表後,該字段纔會出現?選擇列表是否更新它所在的框架? –