繁体   English   中英

如何在Selenium和PHPUnit中处理byClassName

[英]How to deal with byClassName in Selenium and PHPUnit

我有多个具有相同类名且没有id的元素,我需要获取具有类名的第一个元素。 所以可以说html看起来像这样:

<table class="default-table">       
  <thead>
    <tr>    
      <th class="cell"><span class="text"> Title1</span></th>    
      <th class="cell"><span class="text"> Title2</span></th>
      <th class="cell"><span class="text"> Title3</span></th>    
      <th class="cell"><span class="text"> Title4</span></th>    
    </tr>
  </thead>

  <tbody class="tb">
   <tr>      
     <td class="theInput">
     <input type="text" data-type="string" value="" class="text " data-model-key="item1">    
     </td>

     <td class="theInput">
     <input type="text" data-type="string" value="" class="text " data-model-key="item2">  
     </td>

     <td class="theInput">
     <input type="text" data-type="string" value="" class="text " data-model-key="item3">    
     </td>

     <td class="theInput">
     <input type="text" data-type="string" value="" class="text " data-model-key="item4">    
     </td>
   </tr>       
  </tbody>
</table>

现在,我想使用“文本”类设置第一个和第三个输入字段的值,如果我使用的是看起来像这样的java,我找到了一个解决方案:

classElement = driver.findElements(By.className("text")); 
classElement.get(1).value("1234");
classElement.get(3).value("5678");

我不确定它是否会工作,因为我对Java不熟悉,但是看起来很合逻辑,在PHP中有这样的解决方案吗? 还是在这种情况下调用类来访问元素的更好方法?

我找到了一个看起来像这样的解决方案:

$items = $this->elements($this->using('css selector')->value('table.default-table input.text'));


$items[0]->value('1234');
$items[2]->value('5678');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM