2016-03-30 3 views
0

Ich versuche, einige Tabellen zu suchen und klicken Sie auf eine Schaltfläche in einer Zelle einer bestimmten Tabelle. Dies ist mein aktueller CodejQuery Suche mehrere Tabellen für Text und klicken Sie auf eine Schaltfläche, wenn Text gefunden wird

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 
     } 
    }) 
} 

Dies ist das Ergebnis von $ ist (this) .text():

John 
100% 
05/09/2013 
Vote 

Und dies würde das Ergebnis von $ (this) .html() seiner

<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> 

Was ich tun muss, ist, klicken Sie auf die Schaltfläche mit dieser spezifischen ID in diesem Fall '6332'.

Dies ist ein bisschen vollständiger HTML-Code.

<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

Könnten Sie ein komplettes HTML-Beispiel hinzufügen. Was und wo sind die '# compTabs',' .tabNavigation' und '.top_tabs' Elemente? –

+0

Hinzugefügt mehr HTML-Code wie angefordert. – Trax

+1

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

Antwort

1

können Sie versuchen, eine Lösung ohne jQuery, so etwas wie diese:

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" 
); 
Verwandte Themen