2016-10-12 47 views
0

我正在處理我的測試案例,其中包括將值發送到輸入字段以購買票據。但是對於這種情況,硒讓我無法找到元素錯誤,而我試圖找到名爲itemq_3728的輸入字段,問題是頁面在每次重新打開頁面時都會更改輸入字段的名稱。硒,Python。沒有這樣的元素:無法找到元素錯誤,無論按鈕是否存在

如何找到輸入字段? 我嘗試的XPath卻無法實現的目標,也是寫不出它相對於票

<table id="bms_tickets" width="90%" cellspacing="5" cellpadding="0" class="bms_tickets table"> 
      <thead> 
       <tr> 
        <th>NAME</th> 
        <th width="240px">PRICE</th> 

        <th width="100px">QUANTITY</th> 

       </tr> 
      </thead> 
      <tbody id="resTypesTable"> 


<tr id="bms_restype_3728" class="bms_restype"> 
<td class="bms_restype_desc"> 
    Gen Ad 


    <div style="font-size:10px;margin-left:5px;"> 

    </div> 
</td>      
<td class="bms_restype_price"> 


      $10.00 
      <input type="hidden" name="pay_itemq_3728" value="10.00"> 



</td> 

<td class="bms_restype_qty">  

       <input type="text" name="itemq_3728" value="0" placeholder="1" min="1"> 
</td> 

</tr> 
      </tbody> 
      </table> 

回答

0

希望這將幫助頁面加載後假設的名稱更改只有數字路徑的名稱: '//td[@class="bms_restype_qty"]//input[starts-­‐with(@name,"itemq")]'

0

您可以如下使用cssSelector找到它: -

driver.find_element_by_css_selector("td.bms_restype_qty > input[type='text']") 

或者,如果你有興趣來定位使用該元素xpath可以找到它,如下WRT Gen Ad名稱列文本: -

driver.find_element_by_xpath(".//td[normalize-space(.)='Gen Ad' and @class = 'bms_restype_desc']/following-sibling::td[@class='bms_restype_qty']/input") 

或者

driver.find_element_by_xpath(".//tr[td[normalize-space(.)='Gen Ad']]/td[@class='bms_restype_qty']/input") 
相關問題