Get only visible text currently present on a tab of a webpage

559 views
Skip to first unread message

amit

unread,
Aug 18, 2011, 5:40:49 PM8/18/11
to Selenium Users
Hi everyone,
I am facing a problem here. As the subject says, I need to get all the
visible text currently present on a tab of a webpage.

For example,
If the webpage is: http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/tabs/tabs.aspx
I want to know how to get text only for the currently selected tab.
Currently, since "Signature and Bio" tab is selected, I want to
capture text which should include
"""
Signature:
Bio:
"""

but NOT text from other tabs.
"""
Email:

Controls authored by Toolkit User (read-only - demo purposes):
Calendar
MaskedEdit
Accordion
Calendar
Calendar
"""

I am using selenium2.2 RC standalone server with Python client. I know
there is a method called get_body_text(), but it gets me all the text
present in the html page. I am pretty sure that we need to use
get_eval() method to get the current text. I am not that good with
JavaScript, so if anyone knows how to get the current text shown to
the user using Javascript, please share it?!

Also, using JS, I want to know if there is a way to know if the tab is
selected?

Thanks a lot,
Amit

Luke Inman-Semerau

unread,
Aug 19, 2011, 3:53:57 PM8/19/11
to seleniu...@googlegroups.com
No javascript necessary

from selenium import webdriver
ff = webdriver.Firefox()
print ff.find_element_by_id("ctl00_SampleContent_Tabs_body").text
print ff.find_element_by_css_selector("#ctl00_SampleContent_Tabs .ajax__tab_active").text

Will show the text the user sees.


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


amit

unread,
Aug 22, 2011, 10:55:18 AM8/22/11
to Selenium Users, luke.s...@gmail.com
This is great!! Thanks a lot Luke. But since I am using Selenium RC,
how do I do the same from Selenium RC:-

I am using the following code with Selenium RC, but it returns me the
entire text!!

from selenium import selenium
s = selenium('localhost', 4444, '*chrome', 'http:///')
s.open("http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/
tabs/tabs.aspx")
print s.get_text("ctl00_SampleContent_Tabs_body")

This returns all the text
"""
u'Signature:\nBio:\n \n\nHit Save to cause a postback from an update
panel inside the tab panel.\n\nEmail: \n\n \n\nHit Save to cause a
full postback
. \nControls authored by Toolkit User (read-only - demo purposes):
\nCalendar\nMaskedEdit\nAccordion\nCalendar\nCalendar'
"""

Any suggestions???

Thanks,
Amit

On Aug 19, 1:53 pm, Luke Inman-Semerau <luke.seme...@gmail.com> wrote:
> No javascript necessary
>
> from selenium import webdriver
> ff = webdriver.Firefox()
> ff.get("http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/tabs/tabs...")
> print ff.find_element_by_id("ctl00_SampleContent_Tabs_body").text
> print
> ff.find_element_by_css_selector("#ctl00_SampleContent_Tabs
> .ajax__tab_active").text
>
> Will show the text the user sees.
>
>
>
>
>
>
>
> On Thu, Aug 18, 2011 at 2:40 PM, amit <wilson.a...@gmail.com> wrote:
> > Hi everyone,
> > I am facing a problem here. As the subject says, I need to get all the
> > visible text currently present on a tab of a webpage.
>
> > For example,
> > If the webpage is:
> >http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/tabs/tabs...

Luke Inman-Semerau

unread,
Aug 22, 2011, 12:58:11 PM8/22/11
to amit, Selenium Users
Since you're using python and this is supposedly new code... move forward with webdriver:

from selenium import webdriver

Sorry I can't be much more help with RC... i don't use it / know it that well. Not sure if there's an equivalent to getting visible text in RC.
Reply all
Reply to author
Forward
0 new messages