【问题标题】:Selenium PHPUnit select element by label textSelenium PHPUnit 按标签文本选择元素
【发布时间】:2015-04-25 01:29:15
【问题描述】:

我有以下 HTML 代码 sn-p:

<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();

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

【问题讨论】:

    标签: selenium xpath selenium-webdriver webdriver phpunit


    【解决方案1】:
    //div[@class='radio']//*[contains(.,'Second descriptive title ')]//input[@type='radio']
    

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

    【讨论】:

      猜你喜欢
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多