Search code examples
codeceptioncodeceptjs

Click on first element contained in a div


I have a div that contains a set of dynamic elements. I want to click on the first search result.

Here is what the HTML looks like.

I want to click on the first element contains in

I tried using creating a custom xPath like so but it didn't work. Any ideas here?

//div[1][contains(text(), 'listing')]

Solution

  • First of all It would've helped if you had provided more information.

    best will be using pseudo-child like div.firstChild or if the elements are generated dynamically you can add a class and use document.querySelectorAll(".class") which will give you an array of elements that had the class.

    You can use array[0] to use click on the first element.