WebDriver: Any way to get the HTML from a WebElement?

1,287 views
Skip to first unread message

laredotornado

unread,
Nov 30, 2011, 11:21:15 AM11/30/11
to Selenium Users
Hi,

I'm using Selenium 2.12 and trying to interact with the WebDriver api
in my JUnit test. Is there any way, once I get a WebElement, that I
can figure out what HTML the WebElement contains? That would be
massively useful.

Massive thanks in advance, - Dave

Krishnan Mahadevan

unread,
Nov 30, 2011, 11:33:52 AM11/30/11
to seleniu...@googlegroups.com
WebElement.getTagName()
WebElement.getAttribute(String attribName);
WebElement.getText();

These methods can be used to get some information about a WebElement.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


Luke Inman-Semerau

unread,
Nov 30, 2011, 11:39:59 AM11/30/11
to seleniu...@googlegroups.com
Dave,

You can always use the JavascriptExecutor to do a lot of things with it too (like get the innerHTML):

String html = (String)((JavascriptExecutor)driver).executeScript("return arguments[0].innerHTML;", element);

-Luke

laredotornado

unread,
Nov 30, 2011, 2:45:13 PM11/30/11
to Selenium Users
Thanks, Luke! I really like the slick one liner, - Dave

On Nov 30, 10:39 am, Luke Inman-Semerau <luke.seme...@gmail.com>
wrote:


> Dave,
>
> You can always use the JavascriptExecutor to do a lot of things with it too
> (like get the innerHTML):
>
> String html = (String)((JavascriptExecutor)driver).executeScript("return
> arguments[0].innerHTML;", element);
>
> -Luke
>
> On Wed, Nov 30, 2011 at 8:33 AM, Krishnan Mahadevan <
>
>
>
>
>
>
>
> krishnan.mahadevan1...@gmail.com> wrote:
> > WebElement.getTagName()
> > WebElement.getAttribute(String attribName);
> > WebElement.getText();
>
> > These methods can be used to get some information about a WebElement.
>
> > Thanks & Regards
> > Krishnan Mahadevan
>
> > "All the desirable things in life are either illegal, expensive, fattening
> > or in love with someone else!"
>

Reply all
Reply to author
Forward
0 new messages