2017-04-26 8 views
0

以下は、HTMLのセクションです。問題があります。セレンとC#|どのようにしてテーブルのボタンをクリックできますか?

私がしようとしていること:現在、セレンのクロームドライバを使用して、ウェブサイト上にチケットを作成するプロセスを行っています。特定のページでは、いくつかのチェックボックスをチェックするためにタブを選択する必要があります(下記参照)。しかし、それらはすべて同じIDを持っています。どのようにC#でセレニウムのクロムドライバを使用して(2番目の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

私はすべてのTOP_TAB要素(必要なものまでループ)を選択し、次にすべてのTOP_BUTTONを探すための2番目のXPathを実行します(必要なインデックスを繰り返して選択します) –

答えて

0

それは常に(ボタンのと同じ考え方)あなたがこれを行うことができます2つ目のタブになるだろう知っている場合。

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

他の人がそれが正しいことを知ってもらえるように働いたら、答えを受け入れるように自由に感じてください:) –

関連する問題