I want to use executeJS from Codeception to click on an element for which I'm using a xpath locator. I know this is very simple when using it with document.getElementById. But I've tried using it with an xpath, and I can't make it to work. The line that's giving me headaches is :
$this->executeJS('$(\'(//*[@id="openOrders-table"]/tbody/tr[contains(., "Open")]//button[@type="button"])[1]\').click();'); it gives: Cannot read property 'click' of null
If I do a search in the DOM, it finds the element, everything is ok if I use it without JS.
The reason for which I want to ise JS is because the click from JS automatically scrolls to the element and clicks on it. The scrollTo from Codeception doesn't help me much. the element is not in the same place all the time. Appreciate the time guys!
Openstatus. The xpath is correct, as I've stated before, I'm able to find it in the DOM by pressing CRTL+F then pasting the xpath expression, it returns 1 result, the desired button.