2017-04-26 1 views
0

Unten ist ein Teil von HTML, mit dem ich Probleme habe.Selen & C# | Wie kann ich auf eine Schaltfläche in einer Tabelle klicken?

Was ich versuche zu tun: Ich verwende derzeit Selenium-Chrom-Treiber, um den Prozess der Erstellung eines Tickets auf einer Website zu durchlaufen. Auf einer bestimmten Seite muss ich einen Tab auswählen, um ein paar Checkboxen zu aktivieren (siehe unten). Sie haben jedoch alle die gleiche ID. Wie kann ich wählen (sagen die 2. TOP_TAB & TOP_BUTTON) mit Selenium-Chrom-Treiber in C# und klicken Sie auf das Element.

<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

Ich werde XPath tun, um alle TOP_TAB Elemente auszuwählen (Schleife bis es die eine ist) und dann einen 2. XPath nach allen TOP_BUTTON suchen (Iterieren und wählen Sie den Index, den ich brauche) –

Antwort

0

Wenn Sie wissen, es wird immer die zweite Registerkarte, die Sie diese (und gleiche Idee für die Schaltfläche) tun können.

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

wenn Sie nicht wissen, dass es die zweite sein wird, aber wissen Sie das mit Addendum 01 drin, dann können Sie dies tun:

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

der zweite Weg bekommt man die Artikel, den Sie möchten, und gehen Sie dann zurück zu dem Tab, den Sie möchten.

+0

Dieser erste funktionierte perfekt. Danke dir dafür. –

+0

Fühlen Sie sich frei, die Antwort zu akzeptieren, wenn es funktioniert, damit andere wissen, dass es korrekt ist :) –

Verwandte Themen