0

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!

2
  • You should use css, please provide the HTML snippet of the form if possible if you need help in getting the css selector. For xpath take a look at stackoverflow.com/questions/6466831/… Commented May 3, 2017 at 10:11
  • css is not an option unfortunately, as I'm selecting parent/child/child, because it's a table of multiple lines, and there are multiple elements with the same id/class. This is the only selector option that narrows it down to a unique element, the first line with Open status. 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. Commented May 3, 2017 at 11:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.