2016-03-30 1 views
0

テーブルを検索して特定のテーブルのセル内のボタンをクリックしようとしています。これは私の現在のコードjQuery複数のテーブルを検索し、テキストが見つかるとボタンをクリック

links[1].click(); 
iimPlayCode('WAIT SECONDS = 2') 
var compTabs = window.content.document.getElementById('compTabs') 
var compTabList = compTabs.getElementsByClassName("tabNavigation top_tabs") 
if (compTabList[0].children[0].innerText.match(/voting/gi)) { 
    $('#candidatesList').each(function() { 
     if ($(this).text().match(/john/gi)) { // search for text 
      // everything works fine until here, don't know how to click the specific button   
      //get id of button and click it 
     } 
    }) 
} 

これは、$(この)は.text()の結果です。

John 
100% 
05/09/2013 
Vote 

そして、これは$(この)の.html()

の結果だろう
<tr style="text-align: center;"> 
    <td><img src="http://somewebsite.com" width="36px"></td> 
    <td>John</td> 
    <td>100%</td> 
    <td>05/09/2013</td> 
    <td class="last-child"><button rel="123" id="6332" class="button_85 sa_vote">Vote</button></td> 
</tr> 

私がしなければならないことは、この特定のIDを持つボタンをクリックすることです '6332'。

これはもう少し完全なHTMLコードです。

<div id="compTabs"> 
          <div class="tabs"> 
           <ul class="tabNavigation top_tabs"> 
                     <li rel="#tab_voting" class="selected"> 
              <table cellspacing="0" cellpadding="0"> 
                <tbody><tr> 
                  <td width="28px"><img src="http://somewebsite.com/design/img/new_style/tabs/voting.png"></td> 
                  <td>Voting</td> 
                </tr> 
              </tbody></table> 
            </li> 
                     <li rel="#tab_shareholders"> 
              <table cellspacing="0" cellpadding="0"> 
                <tbody><tr> 
                  <td width="28px"><img src="http://somewebsite.com/design/img/new_style/tabs/shareholders.png"></td> 
                  <td>Shareholders</td> 
                </tr> 
              </tbody></table> 
            </li> 
           </ul> 

                   <div class="compTabsContent" id="tab_voting" style="display: block;">  
<div style="height:390px;margin:0;" class="companyBody"> 

     <table cellspacing="0" cellpadding="0" width="100%" style="margin-top: 10px;" class="proTable"> 
      <tbody><tr valign="top"> 
       <td style="text-align:center;height:35px;vertical-align:middle;font-size:14px;"> 
        Vote to elect <b style="color:red"> General Director </b>.     <div id="startTimer" class="timerStyle01">1d 22h:13m:30s</div> 
       </td> 
      </tr> 
     </tbody></table> 

     <table cellspacing="0" cellpadding="0" width="100%" style="margin-top:10px"> 
      <tbody><tr valign="top"><td width="35%"> 
       <table cellspacing="0" cellpadding="0" class="proTable newTable"> 
        <thead> 
         <tr><th class="thb" colspan="3">All shareholders</th></tr> 
         <tr> 
          <th width="36px">&nbsp;</th> 
          <th>Shareholder name</th> 
          <th>He voted</th> 
        </tr></thead> 
        <tbody id="listOfAdministrators"> 

            <tr style="text-align: center;"> 
            <td><img width="36px" src="http://somewebsite.com/content/user/small/user_1364379268_234.jpg"></td> 
            <td>John</td> 
            <td><img src="http://somewebsite.com/design/img/new_style/tabs/no.png"></td> 
            </tr> 
                </tbody> 
       </table> 
      </td> 
      <td width="10px"></td> 
      <td> 
       <table cellspacing="0" cellpadding="0" class="proTable newTable"> 
          <thead> 
           <tr><th class="thb" colspan="5">Vote to elect <b style="color:red"> General Director </b>.</th></tr> 
           <tr> 
            <th width="36px">&nbsp;</th> 
            <th>Shareholder name</th> 
            <th>Shares</th> 
            <th>Date of shares purchase</th> 
            <th>&nbsp;</th></tr> 
          </thead> 
          <tbody id="candidatesList"> 

               <tr style="text-align: center;"> 
                <td><img width="36px" src="http://somewebsite.com/content/user/small/user_1364379268_234.jpg"></td> 
                <td>John</td> 
                <td>100%</td> 
                <td>05/09/2013</td> 
                <td class="last-child"><button class="button_85 sa_vote" id="60928" rel="234">Vote</button></td> 
               </tr> 
                     </tbody> 
       </table> 
      </td></tr> 
     </tbody></table> 


</div></div> 
                   <div class="compTabsContent" id="tab_shareholders" style="display: none;"><div style="height:390px;margin:0;" class="companyBody"> 
    <table cellspacing="0" cellpadding="0" style="margin-top:15px;font-size: 11px;" class="proTable newTable"> 
     <thead> 
      <tr><th style="font-size:13px;" class="thb" colspan="4">All shareholders</th></tr> 
      <tr> 
       <th width="36px" style="border-left: 1px solid #d2d2d2;">&nbsp;</th> 
       <th>Shareholder name</th> 
       <th>Shares</th> 
       <th>Date of shares purchase</th> 
      </tr> 
     </thead> 
     <tbody> 

          <tr style="text-align: center;"> 
           <td><img width="36px" src="http://somewebsite.com/content/user/small/user_1364379268_234.jpg"></td> 
           <td>John</td> 
           <td>100%</td> 
           <td class="last-child">05/09/2013</td> 
          </tr> 
           </tbody> 
    </table> 
</div></div> 
          </div> 
         </div> 
+0

あなたはより完全なHTMLの例を追加することができます。 '#compTabs'は何処でどこで、' .tabNavigation'は '.top_tabs'要素ですか? –

+0

要求どおりに追加されたHTMLコードを追加しました。 – Trax

+1

mayve '$(this).find( 'button')。click()'? – lukbl

答えて

1

あなたはこのような何か、jQueryのせずに解決策を試してください:

links[1].click(); 
iimPlayCode(
    "WAIT SECONDS=2" + "\n" + 
    "TAG POS=1 TYPE=TBODY ATTR=ID:candidatesList" + "\n" + 
    "TAG POS=R-1 TYPE=* ATTR=*" + "\n" + 
    "TAG POS=R1 TYPE=TD ATTR=TXT:*john*" + "\n" + 
    "TAG POS=R1 TYPE=BUTTON ATTR=TXT:Vote" + "\n" 
); 
関連する問題