Use Python/WebDriver to get text between <element></element> tags

3,309 views
Skip to first unread message

David Borin

unread,
Aug 10, 2011, 4:56:50 PM8/10/11
to Selenium Users
Given something like:

<body>Hello World</body>

Is there a way to get the "Hello World" text using just WebDriver and
no Javascript hackiness? Given something like:

driver = webdriver.Chrome()
driver.get('mypage.html')
mytext = driver.find_element_by_tag_name('body')

How can I get the text that is between the body tags? I can do it
using some Javascript hackery, but I'm looking for a built-in method
in the Python bindings.

Krishnan Mahadevan

unread,
Aug 11, 2011, 11:28:45 AM8/11/11
to seleniu...@googlegroups.com
I dont know python. But here's how I would do it in Java

driver.findElement(By.xpath("//body")).getText();

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.


David Borin

unread,
Aug 11, 2011, 12:23:56 PM8/11/11
to Selenium Users
Turns out the issue was with the ChromeDriver and the version of
Chrome I was using. I updated the ChromeDriver v14.x and it seemed to
have resolved itself (as in, driver.find_element_by_tag_name(tag).text
started working again)

Thanks!

On Aug 11, 8:28 am, Krishnan Mahadevan
<krishnan.mahadevan1...@gmail.com> wrote:
> I dont know python. But here's how I would do it in Java
>
> driver.findElement(By.xpath("//body")).getText();
>
> 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