2015-02-23 127 views
0

硒PHPUnit的选择元素,我有以下的HTML代码片段:通过标签文本

<div class="modal-body" style="max-height: 317px;"> 
    <div class="radio"> 
     <label> 
     <input type="radio" name="template" value="5"> 
     <img src="/img/custom-icons/Monitor.png" style="height: 24px"> 
     First descriptive title      
     <p class="text-muted">Some description text</p> 
     </label> 
    </div> 
    <div class="radio"> 
     <label> 
     <input type="radio" name="template" value="37"> 
     <img src="/img/custom-icons/Monitor.png" style="height: 24px"> 
     Second descriptive title     
     <p class="text-muted"></p> 
     </label> 
    </div> 
    <div class="radio"> 
     <label> 
     <input type="radio" name="template" value="46"> 
     <img src="/img/custom-icons/Chart_Area_Up.png" style="height: 24px"> 
     Third descriptive title      
     <p class="text-muted">Some text that describes an item.</p> 
     </label> 
    </div> 
</div> 

我想通过它的标签文本选择电台元素并单击它。我在做什么:

$this->byXPath("//label[text()='Second descriptive title']")->click(); 

不幸的是,这是行不通的。有任何想法吗?我将不胜感激您的帮助。

回答

2
//div[@class='radio']//*[contains(.,'Second descriptive title ')]//input[@type='radio'] 

非常棘手。可能有更好的方法。但是,这是我可以建议的。做一个tag独立搜索self//*[contains(.,'Second descriptive title')]和之后,只是步行到input电台tag