Skip to content

Commit

Permalink
Fixing "getText" method returning an empty value on a visible element
Browse files Browse the repository at this point in the history
  • Loading branch information
aik099 committed Nov 1, 2024
1 parent 6f4e09d commit 3fc6c5d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,11 @@ public function getTagName(string $xpath)

public function getText(string $xpath)
{
$node = $this->findElement($xpath);
$text = $node->text();
$text = (string) str_replace(array("\r", "\r\n", "\n"), ' ', $text);

return $text;
return (string) str_replace(
array("\r", "\r\n", "\n"),
' ',
$this->executeJsOnXpath($xpath, 'return {{ELEMENT}}.innerText;')
);
}

public function getHtml(string $xpath)
Expand Down

2 comments on commit 3fc6c5d

@olivier1980
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bug of some elements return an empty string cost me half a day of debugging, hope it gets released soon

@aik099
Copy link
Member Author

@aik099 aik099 commented on 3fc6c5d Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olivier1980 , could you provide a minimalistic test case (HTML and PHP), that would demonstrate when exactly the original (prior to this commit) behavior of the getText method is causing an issue?

P.S.
Better to create a new issue/PR in this repo, because comments on commits aren't easily visible to everyone.

Please sign in to comment.