MinkSelenium2Driver icon indicating copy to clipboard operation
MinkSelenium2Driver copied to clipboard

Use "innerText" attribute in getText() method

Open yyss8 opened this issue 2 years ago • 4 comments

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 avatar Feb 17 '23 17:02 yyss8

@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.

aik099 avatar Feb 18 '23 14:02 aik099

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().

mvorisek avatar Mar 01 '23 00:03 mvorisek

@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)?

aik099 avatar May 11 '23 07:05 aik099

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.

mvorisek avatar May 11 '23 10:05 mvorisek