2012-05-02 71 views
0

我試圖刪除點擊通過前面的測試生成的鏈接(刪除鏈接)正確的鏈接,但我使用XPath硒沒有找到使用XPath

這裏有很大的困難,我收到

錯誤
Invalid response while accessing the Selenium Server at 'http://localhost:4444/s 
elenium-server/driver/': ERROR: Element xpath=(//td[normalize-space() ='Test tit 
le 2']/following-sibling::td[3]/descendant::a[.='delete']) not found 

這裏是我的測試

public function testdeleteStationTestCase() 
    { 
     $this->open("/upd8r_new/"); 
     $this->click("css=a > img"); 
     $this->waitForPageToLoad("30000"); 
     $this->type("name=username", "glass2"); 
     $this->type("name=password", "glass2"); 
     $this->click("name=submit"); 
     sleep(1); 
     $this->click("xpath=(//td[normalize-space() ='Test title 2']/following-sibling::td[3]/a[.='delete'])"); 
     //$this->click("xpath=(//td[normalize-space() ='Test title 2']/following-sibling::td[3]/descendant::a[.='delete'][1])"); 

     sleep(1); 


     $this->assertTrue($this->isTextPresent("Station deleted!"),"Station Deleted"); 
    } 

,你可以看到我的註釋行,我一直在嘗試各種組合,以獲得測試運行 -

這裏是我測試反─我添加了一行文字,其中我試圖點擊

<body> 
<!-- social media header --> 
<div class="main"> 
    <div class="header"> 
     Central Control Panel 

    </div> 

    <div class="logo"> 
        <img src="http://localhost/upd8r_new/imgs/loyalty_connect2.png"/> 
      </div> 

    <div style="clear:both"></div> 



    <ul class="Menu" id="maintab"> 
     <li class="selected" rel="home"><a href="http://localhost/upd8r_new/socialmedia">HOME</a>  </li> 

     <li rel="retail"> 
      <a href="http://localhost/upd8r_new/social_retail">RETAIL</a>  </li> 




     <li rel="stats"> <a href="http://localhost/upd8r_new/socialmedia/stats">STATS</a></li> 
     <li 






      rel="social_media_settings"> <a href="http://localhost/upd8r_new/socialmedia/settings">SETTINGS</a></li> 
     <li rel="logout"><a href="http://localhost/upd8r_new/login/logout">LOGOUT</a> </li> 
    </ul> 


    <div style="clear:both"></div> 
    <div style="text-align:left;width:980px;height:40px;background-color:#0E477A;margin:auto;padding-top:0px;"> 

     <div style="width:700px;text-align:left;padding-left:10px;float:left"> 

      <div id="logout" class="submenustyle"> 

      </div> 
         <div id="retail" class="submenustyle"> 
       <ul class="sub_menu"> 
        <li><a href="http://localhost/upd8r_new/social_retail">USERS</a></li> 
        <li><a href="http://localhost/upd8r_new/social_retail/view_competitions">COMPETITIONS</a></li> 

       </ul>    
      </div> 
         <div id="home" class="submenustyle"> 
       <ul class="sub_menu"> 
        <li><a href="http://localhost/upd8r_new/socialmedia/add">ADD LIKESTATION</a></li> 
        <li><a href="http://localhost/upd8r_new/socialmedia/add_picstation">ADD PICSTATION</a></li> 
        <li><a href="http://localhost/upd8r_new/socialmedia/add_vidstation">ADD VIDSTATION</a></li> 
       </ul> 

      </div> 
      <div id="socialmedia_users" class="submenustyle"> 

      </div> 
      <div id="stats" class="submenustyle"> 
       <ul class="sub_menu"> 
        <li><a href="http://localhost/upd8r_new/socialmedia/stats">STATS HOME</a></li> 
        <li><a href="http://localhost/upd8r_new/socialmedia/stats/facebook/stats">FACEBOOK STATS</a></li> 


       </ul> 
      </div> 


      <div id="social_media_settings" class="submenustyle"> 
       <ul class="sub_menu"> 
        <li><a href="http://localhost/upd8r_new/socialmedia/settings">SETTINGS HOME</a></li> 
        <li><a href="http://localhost/upd8r_new/socialmedia/registration_settings">NETWORKS TO USE</a></li> 

        <li><a href="http://localhost/upd8r_new/socialmedia/pre_settings">PRE REGISTRATION</a></li> 
              <li> 
         <a href="http://localhost/upd8r_new/socialmedia/app_settings">APP SETTINGS</a>     
         </li> 
            </ul> 
      </div> 


     </div> 
     <div style="float:right;font-weight:bold;color:#fff;margin-top:12px;margin-right: 20px;"> 
         Logged In As: glass2  </div> 

    </div> 
    <div style="clear:both"></div> 


    <div style="padding-top:30px;padding-left:10px">Station deleted! </div> 
    <div style="padding-left:10px"> 



         <table width="700px" align="left" style="text-align:left;"> 
      <tr> 
       <td style="font-weight:bold">Pre-Registration</td> 
       <td><a href="http://localhost/upd8r_new/retail/register/80">http://localhost/upd8r_new/retail/register/80</a></td> 
      </tr> 

     </table> 
       <div style="clear:both"></div> 

     <table width="800px" align="left" style="text-align:left;"> 
      <tr style="font-weight:bold;background-color:#f1f1f1"> 
       <td colspan="6" STYLE="text-align:center;font-weight:bold">LIKESTATIONS</td> 
      </tr> 
      <tr style="font-weight:bold;background-color:#f1f1f1"> 
       <td width="10%">STATION ID</td> 
       <td width="32%">STATION NAME</td> 
       <td width="25%">LINK TITLE</td> 
       <td width="10%">STATION STATS</td> 
       <td width="15%">LAST POST</td> 
       <td width="8%"></td> 

      </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit/gla20311344">gla20311344</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit/gla20311344">http://localhost/upd8r_new/socialmedia/edit/gla20311344</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit/gla20311344">Webcast</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla20311344">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla20311344">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit/gla2084629867">gla2084629867</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit/gla2084629867">http://localhost/upd8r_new/socialmedia/edit/gla2084629867</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit/gla2084629867">tes this link title3</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla2084629867">STATS</a> </td> 
        <td>4 weeks ago</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla2084629867">delete</a></td> 
       </tr> 
        </table> 

     <div style="clear:both"></div> 

     <table width="620px" align="left" style="text-align:left;"> 
      <tr style="font-weight:bold;background-color:#f1f1f1"> 
       <td colspan="5" STYLE="text-align:center;font-weight:bold">FACEBOOK PIC STATIONS</td> 
      </tr> 
      <tr style="font-weight:bold;background-color:#f1f1f1"> 
       <td width="15%">STATION ID</td> 
       <td width="50%">STATION TITLE</td> 
       <td width="10%">STATION STATS</td> 
       <td width="15%">LAST POST</td> 
       <td width="10%"></td> 

      </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla1079978359">gla1079978359</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla1079978359">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla1079978359">STATS</a> </td> 
        <td>0</td> 
        <td>**link I'm trying to click**<a href="http://localhost/upd8r_new/socialmedia/delete/gla1079978359">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla1229158969">gla1229158969</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla1229158969">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla1229158969">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla1229158969">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla1256364596">gla1256364596</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla1256364596">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla1256364596">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla1256364596">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla1529784490">gla1529784490</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla1529784490">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla1529784490">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla1529784490">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla159062284">gla159062284</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla159062284">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla159062284">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla159062284">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla175038477">gla175038477</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla175038477">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla175038477">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla175038477">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla1777127061">gla1777127061</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla1777127061">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla1777127061">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla1777127061">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla180142977">gla180142977</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla180142977">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla180142977">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla180142977">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla1950664292">gla1950664292</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla1950664292">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla1950664292">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla1950664292">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla1971709701">gla1971709701</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla1971709701">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla1971709701">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla1971709701">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla2028774169">gla2028774169</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla2028774169">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla2028774169">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla2028774169">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla2035285297">gla2035285297</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla2035285297">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla2035285297">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla2035285297">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla2072665757">gla2072665757</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla2072665757">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla2072665757">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla2072665757">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla2115042517">gla2115042517</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla2115042517">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla2115042517">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla2115042517">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla2141659529">gla2141659529</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla2141659529">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla2141659529">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla2141659529">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla4705592">gla4705592</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla4705592">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla4705592">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla4705592">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla565900575">gla565900575</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla565900575">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla565900575">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla565900575">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla608150382">gla608150382</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla608150382">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla608150382">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla608150382">delete</a></td> 
       </tr> 
          <tr> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla979271929">gla979271929</a> </td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/edit_picstation/gla979271929">Test title 2</a> </td> 
        <td><a href="http://localhost/upd8r_new/stats/home/station_stats/gla979271929">STATS</a> </td> 
        <td>0</td> 
        <td><a href="http://localhost/upd8r_new/socialmedia/delete/gla979271929">delete</a></td> 
       </tr> 
        </table> 

     <div style="clear:both"></div> 

     <table width="520px" align="left" style="text-align:left;"> 
      <tr style="font-weight:bold;background-color:#f1f1f1"> 
       <td colspan="4" STYLE="text-align:center;font-weight:bold">FACEBOOK VIDEO STATIONS</td> 
      </tr> 
      <tr style="font-weight:bold;background-color:#f1f1f1"> 
       <td width="20%">STATION ID</td> 
       <td width="60%">STATION TITLE</td> 
       <td width="60%">STATION STATS</td> 
       <td width="20%"></td> 
      </tr> 
        </table> 


     <div style="clear:both"></div> 


</div> 
</div> 
<div class="footer"> 
    <div style="float:left;padding-top:20px;padding-left:20px;font-size:10px;font-family:arial"></div> 
    <div style="padding-top:20px;float:right;padding-right:30px;"><img src="http://localhost/upd8r_new/imgs/excelerated.jpg"/></div> 
</div> 
</body> 
</html> 
+0

註釋行不等於我在我以前的答案:)建議所有這些括號是無用的硒只選擇第一次出現默認 –

回答

1

你的問題是sleep(1); 在這個地方,而不是sleep(1);你應該使用這樣的:

$this->waitForCondition("selenium.isElementPresent(\'css=table:contains(\'FACEBOOK PIC STATIONS\') a:contains(\'delete\')\')", "20000"); 

順便說一下,當你使用硒RC你可以達到你這個CSS刪除鏈接(與webdriver的它不會爲:contains工作,是一項CSS規範)的:

$this->click("css=table:contains('FACEBOOK PIC STATIONS') a:contains('delete')"); 

也全部更換sleep(1);適當waitForCondition命令

+0

謝謝你,但seleium現在返回無效的響應,同時訪問Selenium服務器在'http:// localhost:4444/s elenium-server/driver/':missing)在參數列表後 –

+0

@ChrisMccabe可能你錯過了')'某處。不堆棧跟蹤指向你有問題的行嗎? –

+0

它與waitforcondition行有關...我把它複製完全。我得到了測試通過給Facebook的臺站表一個ID和使用$ this-> waitForCondition(「selenium.isElementPresent('id = facebook_vid_stations')」,「20000」); –

0

安裝「的XPath 4.4檢查」在Firefox附加組件的HTML頁面。因此,對於該對象,你會使用這個插件得到適當的XPath ..

所以,

點擊的XPath = XPath的那個對象

+0

我已經做到了這一點,並使用xpath檢查器找到對象 –