点击selenium webdriver

时间:2017-02-14 05:47:26

标签: java selenium-webdriver click

我陷入困境,我必须点击特定的图片图标才能展开选择。

  

这是

的HTML代码

<table role="presentation" class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="width:1043px;height:21px;">
  <tbody role="presentation">
    <tr role="presentation">
      <td id="x-auto-354" role="gridcell" class="x-grid3-col x-grid3-cell x-grid3-td-Child:number x-grid-cell-first  x-treegrid-column" style="width:202px;">
        <div unselectable="on" class="x-grid3-cell-inner cat-x-grid3-cell-inner x-grid3-col-Child:number">
          <div role="presentation" unselectable="on" class="x-tree3-el">
            <img src="http://plmtest.lenovo.com/Windchill/gwt/com.ptc.windchill.wncgwt.WncGWT/clear.gif" style="height: 18px; width: 18px;">
            <img src="http://plmtest.lenovo.com/Windchill/gwt/com.ptc.windchill.wncgwt.WncGWT/clear.cache.gif" style="width: 16px; height: 16px; background: url(http://plmtest.lenovo.com/Windchill/gwt/com.ptc.windchill.wncgwt.WncGWT/C4EA130FD0ED44BE513FEEDDE13614DA.cache.png) no-repeat -34px 0px"
            border="0"><span></span><span class="cat-icons-tree"><img src="http://plmtest.lenovo.com/Windchill/gwt/com.ptc.windchill.wncgwt.WncGWT/clear.cache.gif" style="width: 16px; height: 16px; background: url(http://plmtest.lenovo.com/Windchill/./wtcore/images/part.gif) no-repeat 0px 0px;" id="miniInfo_OR:wt.part.WTPart:207216019841642" border="0"><span></span></span>
            <span
            unselectable="on" class="x-tree3-node-text">86000606</span>
          </div>
          <div role="presentation" unselectable="on" id="x-auto-224" class="x-tree3-node"></div>
        </div>
      </td>
      <td id="x-auto-355" role="gridcell" class="x-grid3-col x-grid3-cell x-grid3-td-Child:infoPageAction   " style="width:32px;">
        <div unselectable="on" class="x-grid3-cell-inner cat-x-grid3-cell-inner x-grid3-col-Child:infoPageAction">
          <div title="View Information">
            <a href="app/#ptc1/tcomp/infoPage?oid=VR:wt.part.WTPart:20662978987" target="_top">
              <img src="http://plmtest.lenovo.com/Windchill/netmarkets/images/details.gif" class="gwt-Image">
            </a>
          </div>
        </div>
      </td>
      <td id="x-auto-356" role="gridcell" class="x-grid3-col x-grid3-cell x-grid3-td-Child:state   " style="width:62px;">
        <div unselectable="on" class="x-grid3-cell-inner cat-x-grid3-cell-inner x-grid3-col-Child:state">Production Released</div>
      </td>
      <td id="x-auto-357" role="gridcell" class="x-grid3-col x-grid3-cell x-grid3-td-Link:quantityAmount   " style="width:57px;">
        <div unselectable="on" class="x-grid3-cell-inner cat-x-grid3-cell-inner x-grid3-col-Link:quantityAmount">1</div>
      </td>
      <td id="x-auto-358" role="gridcell" class="x-grid3-col x-grid3-cell x-grid3-td-Child:IBA|basic_name   " style="width:62px;">
        <div unselectable="on" class="x-grid3-cell-inner cat-x-grid3-cell-inner x-grid3-col-Child:IBA|basic_name">86 PART</div>
      </td>
      <td id="x-auto-359" role="gridcell" class="x-grid3-col x-grid3-cell x-grid3-td-Child:IBA|LocationCode   " style="width:62px;">
        <div unselectable="on" class="x-grid3-cell-inner cat-x-grid3-cell-inner x-grid3-col-Child:IBA|LocationCode">DSWP</div>
      </td>
      <td id="x-auto-360" role="gridcell" class="x-grid3-col x-grid3-cell x-grid3-td-Child:IBA|UsageCode   " style="width:62px;">
        <div unselectable="on" class="x-grid3-cell-inner cat-x-grid3-cell-inner x-grid3-col-Child:IBA|UsageCode">DC86</div>
      </td>
      <td id="x-auto-361" role="gridcell" class="x-grid3-col x-grid3-cell x-grid3-td-Link:lineNumber   " style="width:62px;">
        <div unselectable="on" class="x-grid3-cell-inner cat-x-grid3-cell-inner x-grid3-col-Link:lineNumber">40</div>
      </td>
      <td id="x-auto-362" role="gridcell" class="x-grid3-col x-grid3-cell x-grid3-td-Child:name   " style="width:182px;">
        <div unselectable="on" class="x-grid3-cell-inner cat-x-grid3-cell-inner x-grid3-col-Child:name">Warranty Common Group</div>
      </td>
      <td id="x-auto-363" role="gridcell" class="x-grid3-col x-grid3-cell x-grid3-td-Child:docstructure_status   " style="width:17px;">
        <div unselectable="on" class="x-grid3-cell-inner cat-x-grid3-cell-inner x-grid3-col-Child:docstructure_status"></div>
      </td>
      <td id="x-auto-364" role="gridcell" class="x-grid3-col x-grid3-cell x-grid3-td-Child:version   " style="width:102px;">
        <div unselectable="on" class="x-grid3-cell-inner cat-x-grid3-cell-inner x-grid3-col-Child:version">K.5 (Design)</div>
      </td>
      <td id="x-auto-365" role="gridcell" class="x-grid3-col x-grid3-cell x-grid3-td-Link:replacementStatus   " style="width:17px;">
        <div unselectable="on" class="x-grid3-cell-inner cat-x-grid3-cell-inner x-grid3-col-Link:replacementStatus"></div>
      </td>
      <td id="x-auto-366" role="gridcell" class="x-grid3-col x-grid3-cell x-grid3-td-Child:IBA|bac_code   " style="width:62px;">
        <div unselectable="on" class="x-grid3-cell-inner cat-x-grid3-cell-inner x-grid3-col-Child:IBA|bac_code"></div>
      </td>
      <td id="x-auto-367" role="gridcell" class="x-grid3-col x-grid3-cell x-grid3-td-Child:containerName x-grid3-cell-last  " style="width:62px;">
        <div unselectable="on" class="x-grid3-cell-inner cat-x-grid3-cell-inner x-grid3-col-Child:containerName">CTO_DT</div>
      </td>
    </tr>
  </tbody>
</table>

1 个答案:

答案 0 :(得分:0)

请尝试以下代码:

driver.findElement(By.xpath("//div[@class='x-tree3-el']/img[1]"));

如果不起作用,请尝试以下操作:

driver.findElement(By.xpath("//div[@class='x-tree3-el' and @role='presentation']/img[1]"));

截图参考:

enter image description here