2015-10-27 53 views
0

the HTML TAG HERE通過xpath表查找沒有id,名稱和類的表。硒C#

這裏是HTML關於我的問題,我非常新的的XPath ...我只是想在C#創建一個的XPath其中,我會點擊和時鐘的時鐘out按鈕。我知道我的問題是基本的,但我很難找出答案。

這裏是HTML

<table> 
    <tbody> 
     <tr> 
      <td><img height="1" src="/images/px.gif" width="10"></td> 
      <td align="left"> 
       <table cellspacing="4" class="btn" onmousedown= 
       "return sbtnDown(this);" onmouseout="sbtnOut(this)" 
       onmouseover="sbtnOver(this)" onmouseup= 
       "timeSheetAction2(&quot;TIME_SHEET_PUNCH&quot;,&quot;&quot;,&quot;IN&quot;,true)" 
       width="100%"> 
        <tbody> 
         <tr> 
          <td><img src="/images/20x20/clock_go.png"></td> 
          <td align="left" nowrap width="100%">Clock In</td> 
         </tr> 
        </tbody> 
       </table> 
      </td> 
      <td><img height="1" src="/images/px.gif" width="40"></td> 
      <td align="center"> 
       <table cellspacing="4" class="btn" onclick= 
       "window.showPopUp_Lookup({&quot;center&quot;:1,&quot;w&quot;:780,&quot;title&quot;:&quot;Change Cost Centres&quot;,&quot;singleValue&quot;:1,&quot;h&quot;:800,&quot;url&quot;:&quot;/ta/6118466.admin?rnd=EYH&amp;@impl=zeyt.ta.ui.time.UiControl_ChangeCostCenters&amp;@windowId=QLYTJ&amp;Ext=login&amp;sft=PYPBHDQTFA&amp;@showStackMB=0&amp;@pushOnStack=0&amp;@noBG=1&amp;MyLookupName=CHANGE_COST_CENTERS&amp;which_cc_can_change=1&quot;,&quot;fName&quot;:&quot;z230&quot;});return false;" 
       onmousedown="sbtnDown(this)" onmouseout="sbtnOut(this)" 
       onmouseover="sbtnOver(this)" width="100%"> 
        <tbody> 
         <tr> 
          <td><input name="z230" onchange= 
          "this.chkChng=0;timeSheetAction2(&quot;TIME_SHEET_PUNCH&quot;, this.value, &quot;CHANGE_CC&quot;, true);" 
          type="hidden"><img src= 
          "/images/20x20/clock_refresh.png"></td> 
          <td align="left" nowrap width="100%">Change Department</td> 
         </tr> 
        </tbody> 
       </table> 
      </td> 
      <td><img height="1" src="/images/px.gif" width="40"></td> 
      <td align="right"> 
       <table cellspacing="4" class="btn" onmousedown= 
       "sbtnDown(this)" onmouseout="sbtnOut(this)" onmouseover= 
       "sbtnOver(this)" onmouseup= 
       "timeSheetAction2(&quot;TIME_SHEET_PUNCH&quot;,&quot;&quot;,&quot;OUT&quot;,true)" 
       width="100%"> 
        <tbody> 
         <tr> 
          <td><img src= 
          "/images/20x20/clock_cancel.png"></td> 
          <td align="left" nowrap width="100%">Clock Out</td> 
         </tr> 
        </tbody> 
       </table> 
      </td> 
     </tr> 
    </tbody> 
</table> 

以下是我已經嘗試過的方法,但仍然沒有運氣...

browser.FindElementsByXPath("//td[contains(., 'Clock In')]"); 

browser.FindElementsByXPath("//id('PAGE_BODY')/x:table[1]/x:tbody/x:tr/x:td[2]/x:table/x:tbody/x:tr/x:td[2]"); #I got this xpath using xpather a firefox plugin 
+0

張貼您的圖片 – AndreL

+0

我試過下面這個方法 browser.FindElementsByXPath(「// td [contains(。,'Clock In')]」); browser.FindElementsByXPath(「// id('PAGE_BODY')/ x:table [1]/x:tbody/x:tr/x:td [2]/x:table/x:tbody/x:tr/X:TD [2]「); < - 我用xpather得到這個xpath .. 仍然沒有運氣...... :( – wbxx

+0

編輯您的文章與該代碼@Noel Manarang – AndreL

回答

1

我認爲這應該解決這個問題。

driver.FindElement(By.ClassName("btn")).click(); // For "Clock In" 
driver.FindElements(By.ClassName("btn"))[2].click(); // For "Clock Out" 

點擊該表時鐘在時鐘輸出就足夠了,因爲它有一個像onmouseuponmousedown等事件。沒有必要選擇包含文本「Clock In」或「Clock Out」的td標籤。

+0

謝謝你,但我遇到了一些錯誤'OpenQA.Selenium.NoSuchElementException'... – wbxx

+0

試試這個'xpath(「// table [@ class ='btn'] [1]」)。click()'This should click在_Clock In_上。我假設只有那3個表具有'btn'類。 – JRodDynamite

+0

謝謝@jason,但仍然沒有運氣。 – wbxx

相關問題