无法使用id,Xpath,linkText找到以下元素

时间:2014-09-18 13:07:33

标签: selenium

我正在尝试访问包含文本“001”的<a>元素。我尝试使用DOM ID,XPath和linkText,以及这个JavaScript,但我无法找到它。我怎么能做到这一点?

这是我用来查找<a>元素的JavaScript:

driver.findElement(By.linkText("campcode")).click();

这是HTML代码:

<div class="Layout">
  <div class="PageTitle">
    <div class="Primary-Container Rad5Top">
      <div class="Secondary-Container Rad5Top">
        <div style="padding-bottom: 15px;">
          <div id="SupplyChainTabs">
            <div id="opportunitiesDetails">
              <table id="ActionLinks" class="ColRow-Table internal-qualification tablesorter" width="100%">
                <thead>
                  <tr>
                    <th id="CAMPID" width="250" align="left" style="cursor: pointer;">
                    <th id="CommunityName" width="200" align="left" style="cursor: pointer;">
                    <th id="ProdCode" width="200" align="left" style="cursor: pointer;">
                    <th id="Prospects" width="150" align="left" style="cursor: pointer;">
                    <th id="TS" width="200" align="left" style="cursor: pointer;">
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td valign="top">
                      <a id = "OB.2000003,OB.2000052,OB.2000053,OB.2000054,OB.2000055,OB.2000056,OB.2000057,OB.2000058" class="" onclick="return ButtonClick(this);" href="#f">001</a> <!-- THE ELEMENT -->
                    </td>
                  <td valign="top"> THQS</td>
                  <td valign="top"> THQS</td>
                  <td valign="top"> 8</td>
                  <td valign="top"> 18/09/2014 13:01:13</td>
                </tr>

1 个答案:

答案 0 :(得分:1)

试试这个:

driver.findElement(By.Xpath("//div[@id='opportunitiesDetails']//a[text()='001']")).click();