2017-04-26 91 views
0

下面是我遇到问题的HTML部分。我怎样才能点击一个表中的按钮?

我在试图做的事:我目前使用硒铬驱动程序来完成在网站上创建票证的过程。在某个页面上,我必须选择一个标签才能检查一些复选框(见下文)。但是,它们都具有相同的ID。我如何使用C#中的selenium chrome驱动程序来选择(例如第二个TOP_TAB & TOP_BUTTON),然后单击该元素。

<input type="hidden" name="tabsize" value="5"> 

<td id="TOP_TAB" width="10" class="leftRightBorder" style="width: 5px;"> 
    <table cellpadding="0" cellspacing="0"> 
     <tbody> 
      <tr> 
       <td id="TOP_BUTTON" style="cursor:hand;" onclick="fun_HideShowBlock('0','0');" align="center" nowrap=""><img src="images/left-cor.gif" width="5" height="18" border="0"></td> 
       <td id="TOP_BUTTON" style="cursor: pointer; font-size: 10px; background-color: rgb(181, 200, 217); border-bottom: 2px solid rgb(181, 200, 217); font-weight: normal;" 
        onclick="fun_HideShowBlock('0','0');" align="center" class="drop" nowrap="" bgcolor="#B5C8D9" width="88">Addendum 02</td> 
       <td id="TOP_BUTTON" style="cursor:hand;" onclick="fun_HideShowBlock('0','0');" align="center" nowrap=""><img src="images/right-cor.gif" width="5" height="18" border="0"></td> 
      </tr> 
     </tbody> 
    </table> 
</td> 

<td id="TOP_TAB" width="10" class="leftRightBorder" style="width: 5px;"> 
    <table cellpadding="0" cellspacing="0"> 
     <tbody> 
      <tr> 
       <td id="TOP_BUTTON" style="cursor:hand;" onclick="fun_HideShowBlock('1','1');" align="center" nowrap=""><img src="images/left-cor-light.gif" width="5" height="18" border="0"></td> 
       <td id="TOP_BUTTON" style="cursor: pointer; font-size: 10px; background-color: rgb(217, 223, 239); border-bottom: 0px solid rgb(217, 223, 239); font-weight: bold;" 
        onclick="fun_HideShowBlock('1','1');" align="center" class="drop" nowrap="" bgcolor="#B5C8D9" width="88">Addendum 01</td> 
       <td id="TOP_BUTTON" style="cursor:hand;" onclick="fun_HideShowBlock('1','1');" align="center" nowrap=""><img src="images/right-cor-light.gif" width="5" height="18" border="0"></td> 
      </tr> 
     </tbody> 
    </table> 
</td> 

<td id="TOP_TAB" width="10" class="leftRightBorder" style="width: 5px;"> 
    <table cellpadding="0" cellspacing="0"> 
     <tbody> 
      <tr> 
       <td id="TOP_BUTTON" style="cursor:hand;" onclick="fun_HideShowBlock('2','2');" align="center" nowrap=""><img src="images/left-cor.gif" width="5" height="18" border="0"></td> 
       <td id="TOP_BUTTON" style="cursor: pointer; font-size: 10px; background-color: rgb(181, 200, 217); border-bottom: 2px solid rgb(181, 200, 217); font-weight: normal;" 
        onclick="fun_HideShowBlock('2','2');" align="center" class="drop" nowrap="" bgcolor="#B5C8D9" width="88">Default Job</td> 
       <td id="TOP_BUTTON" style="cursor:hand;" onclick="fun_HideShowBlock('2','2');" align="center" nowrap=""><img src="images/right-cor.gif" width="5" height="18" border="0"></td> 
      </tr> 
     </tbody> 
    </table> 
</td> 

<td id="TOP_TAB" width="10" class="leftRightBorder" style="width: 5px;"> 
    <table cellpadding="0" cellspacing="0"> 
     <tbody> 
      <tr> 
       <td id="TOP_BUTTON" style="cursor:hand;" onclick="fun_HideShowBlock('3','3');" align="center" nowrap=""><img src="images/left-cor.gif" width="5" height="18" border="0"></td> 
       <td id="TOP_BUTTON" style="cursor: pointer; font-size: 10px; background-color: rgb(181, 200, 217); border-bottom: 2px solid rgb(181, 200, 217); font-weight: normal;" 
        onclick="fun_HideShowBlock('3','3');" align="center" class="drop" nowrap="" bgcolor="#B5C8D9" width="88">Default Job</td> 
       <td id="TOP_BUTTON" style="cursor:hand;" onclick="fun_HideShowBlock('3','3');" align="center" nowrap=""><img src="images/right-cor.gif" width="5" height="18" border="0"></td> 
      </tr> 
     </tbody> 
    </table> 
</td> 

<td id="TOP_TAB" width="10" class="leftRightBorder" style="width: 5px;"> 
    <table cellpadding="0" cellspacing="0"> 
     <tbody> 
      <tr> 
       <td id="TOP_BUTTON" style="cursor:hand;" onclick="fun_HideShowBlock('4','4');" align="center" nowrap=""><img src="images/left-cor.gif" width="5" height="18" border="0"></td> 
       <td id="TOP_BUTTON" style="cursor: pointer; font-size: 10px; background-color: rgb(181, 200, 217); border-bottom: 2px solid rgb(181, 200, 217); font-weight: normal;" 
        onclick="fun_HideShowBlock('4','4');" align="center" class="drop" nowrap="" bgcolor="#B5C8D9" width="88">Default Job</td> 
       <td id="TOP_BUTTON" style="cursor:hand;" onclick="fun_HideShowBlock('4','4');" align="center" nowrap=""><img src="images/right-cor.gif" width="5" height="18" border="0"></td> 
      </tr> 
     </tbody> 
    </table> 
</td> 

+0

我将执行XPath来选择所有TOP_TAB元素(循环直到其需要的),然后第二个XPath查找所有的TOP_BUTTON(迭代并选择我需要的索引) –

回答

0

如果你知道它永远是你能做到这一点(的按钮和同样的想法),第二个选项卡。

driver.FindElements(By.Xpath("descendant::td[@id = 'TOP_TAB']"))[1]; 

,如果你不知道,这将是第二个,但知道你需要一个与附录01的话,你可以这样做:

driver.FindElement(By.Xpath("descendant::td[text() = 'Addendum 01']/ancestor::td[@id = 'TOP_TAB']")); 

第二种方式让你的你想要的物品,然后回到你想要的标签。

+0

这第一个工作完美。感谢你的这一点。 –

+0

随时接受答案,如果它的工作,以便其他人会知道它是正确的:) –

相关问题