在Selenium中将Xpath定位器转换为CSS定位器

时间:2010-06-23 19:21:16

标签: css testing selenium

全部,

这个xpath定位器在Firefox中工作正常:

ctl00_ctl00_mainPage_rightColumn_wholeControl_grid_cell2_3_roleX_DDD_L_LBI2T0

这在IE中不起作用。我一直在尝试转换为CSS定位器 没有成功。我想要选择的项目是卖方。这是 整个blob:

<div style="width: 168px; overflow: auto; height: 107px; padding-right: 0px;" class="dxlbd" id="ctl00_ctl00_mainPage_rightColumn_wholeControl_grid_cell2_3_roleX_DDD_L_­D"> 
  <input type="hidden" name="ctl00$ctl00$mainPage$rightColumn$wholeControl$grid$cell2_3$roleX$DDD$L" id="ctl00_ctl00_mainPage_rightColumn_wholeControl_grid_cell2_3_roleX_DDD_L_­VI" value="0">    
   <table cellspacing="0" cellpadding="0" border="0" style="width: 100%; border-collapse: separate;" id="ctl00_ctl00_mainPage_rightColumn_wholeControl_grid_cell2_3_roleX_DDD_L_­LBT"> 
    <tbody> 
     <tr class="dxeListBoxItemRow"> 
      <td class="dxeListBoxItem  dxeListBoxItemSelected" id="ctl00_ctl00_mainPage_rightColumn_wholeControl_grid_cell2_3_roleX_DDD_L_­LBI0T0">Choose</td> 
     </tr> 
     <tr class="dxeListBoxItemRow"> 
      <td class="dxeListBoxItem" id="ctl00_ctl00_mainPage_rightColumn_wholeControl_grid_cell2_3_roleX_DDD_L_­LBI1T0">Buyer</td> 
     </tr> 
     <tr class="dxeListBoxItemRow"> 
      <td class="dxeListBoxItem dxeListBoxItemHover" id="ctl00_ctl00_mainPage_rightColumn_wholeControl_grid_cell2_3_roleX_DDD_L_­LBI2T0">Seller</td> 
     </tr> 
     <tr class="dxeListBoxItemRow"> 
      <td class="dxeListBoxItem" id="ctl00_ctl00_mainPage_rightColumn_wholeControl_grid_cell2_3_roleX_DDD_L_­LBI3T0">Buyer &amp; Seller</td> 
     </tr> 
     <tr class="dxeListBoxItemRow"> 
      <td class="dxeListBoxItem" id="ctl00_ctl00_mainPage_rightColumn_wholeControl_grid_cell2_3_roleX_DDD_L_­LBI4T0">Observer</td> 
     </tr> 
    </tbody> 
   </table> 
  </div> 

任何想法都非常感激。

布莱克

1 个答案:

答案 0 :(得分:1)

您可以通过几种方式找到卖方单元格。要根据单元格的内容使用CSS找到它,请尝试:

css=td:contains(Seller)

如果id是静态的,那么以下内容也应该有效,但是id非常长,这可能会导致问题。我自己没有测试过。

id=ctl00_ctl00_mainPage_rightColumn_wholeControl_grid_cell2_3_roleX_DDD_L_­LBI2T0