Selenium PHPUnit通过标签文本选择元素 [英] Selenium PHPUnit select element by label text

查看:85
本文介绍了Selenium PHPUnit通过标签文本选择元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下HTML代码段:

I have the following HTML code snippet:

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

我想通过其标签文本选择单选元素,然后单击它.我正在尝试做的事情:

I want to select radio element by its label text and click it. What I'm trying to do:

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

不幸的是,这不起作用.有任何想法吗?感谢您的帮助.

Unfortunately that is not working. Any ideas? I would be appreciated for your help.

推荐答案

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

非常棘手.可能有更好的方法.但是,这就是我的建议.用//*[contains(.,'Second descriptive title')]self上进行tag独立搜索,然后步行到input收音机tag

Pretty tricky. There could be a better way. But, this is what I can suggest. Doing a tag independent search on self with //*[contains(.,'Second descriptive title')] and after that just walking to the input radio tag

这篇关于Selenium PHPUnit通过标签文本选择元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆