test
test2
test3
test
test2
test3
test
test2
test3

Find Codeception first elements with more than one CSS class with same name

359 Views Asked by At

I have something like the following markup:

<div class="test">
  <div class="test2">test</div>
  <div class="test2">test2</div>
  <div class="test2">test3</div>
  <div class="test2">test4</div>
 </div

I want to click the first test2 class

2

There are 2 best solutions below

1
user19611551 On

Maybe something like this .test .test2:nth-child(1)

0
Samuel On

Check this cheatsheet, it explains how to get the first element of an html tag : https://devhints.io/xpath

$I->click('(//div[@class="test2"])[1]');

This code should work, just try it here : https://extendsclass.com/xpath-tester.html