Use "innerText" attribute in getText() method
Hi, we recently moved the tests of our Drupal site from using chrome-mink-driver to MinkSelenium2Driver and noticing some of the tests are failing due to an empty string being returned when trying to assert the title of the page.
We found a similar issue here https://github.com/minkphp/MinkSelenium2Driver/issues/193 and it seems to be an upstream issue with Selenium?
It also lead us to this stackoverflow answer and which recommends to use innerText attribute to retrieve the text of the element.
Similar issue reported on Drupal.org
@yyss8 can you please reference the issue on the Selenium side?
I don't understand what Selenium the bug prevents the ->text() method from working on some nodes.
I belive the problem is https://github.com/minkphp/MinkSelenium2Driver/pull/327. I would be happy @aik099 if my original PR can be reconsidered, as the getText() will be than implemented consistently like getHtml().
@yyss8 , would it be possible to rewrite your tests to perform actions/assertions based on user possible actions in the Web Browser (e.g. not checking the text of the elements, that aren't visible on the page)?
Here is how I fixed it in my fork: https://github.com/atk4/behat-mink-selenium2-driver/commit/05e2230c35dc573004880bfd2107d660c7b4790a
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText innerText property is well defined:
As a getter, it approximates the text the user would get if they highlighted the contents of the element with the cursor and then copied it to the clipboard.
If the element itself is not being rendered (for example, is detached from the document or is hidden from view), the returned value is the same as the Node.textContent property.