Skip to content

Access element innerText / innerHTML #825

Answered by OndraM
mraspe asked this question in Q&A
Discussion options

You must be logged in to vote

To get text value of an element, you can use native WebDriver method $element->getText().
To get JavaScript property like innerHTML or childElementCount etc., use getDomProperty() method (see example below).
getAttribute() could be used only to get value of DOM element attribute (like "class", "id", "style" etc.) .

$innerHtml = $driver->findElement($element)->getDomProperty('innerHTML');

See wiki

Alternatively, you can ale use executeScript() to get the same result:

$innerHtml = $driver->executeScript('return arguments[0].innerHtml', $element)

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@rmontanana
Comment options

@OndraM
Comment options

@rmontanana
Comment options

Answer selected by OndraM
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #825 on December 08, 2020 18:12.