2012-05-02 41 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检查器找到对象 –