Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
eTo
Posts : 2
Join date : 2012-07-30

webdriver + python, how to check for presence of text on page? Empty webdriver + python, how to check for presence of text on page?

Mon Jul 30, 2012 4:26 am
Hi.
I'm looking for way to check if certain text visible on page while. Is that possible somehow?
All i could find so far, is to check if certein element if present. But let's assume that there is no clear identification of this element, and text it self is not link, Just need to check if i'ts displayed somewhere on page or not, but can't seem to find any simple way like verify from ide plugin.
And another question, how to identify element that contains searched text?
avatar
Sagot
Posts : 4
Join date : 2012-07-05

webdriver + python, how to check for presence of text on page? Empty Re: webdriver + python, how to check for presence of text on page?

Mon Jul 30, 2012 6:10 pm
1. How do I know whether text is present on the page or not (yes/no) without getting a webelement:

String allPageCode = driver.getPageSource(); - we get a big String with all html code.
allPageCode.contains("some text to look for"); - return true / false is it present on the page or not.

this code is for Java but definitely there are the same functions in python!


2. How to get a webelement if we know just text that it must contain? And how to get to know if this text is VISIBLE (not just existing in page source code)?

We use xpath! How to locate:
Element containing text 't' exactly - //*[.='t']
Element containing text 't' - //E[contains(text(),'t')]

When we get the element by xpath we can verify it's visibility on the page:
element.isDisplayed(); - returns true or false;

this is Java code but there are same functions and methods for python as well.



P.S. I strongly recommend to use this helper tables for XPath https://docs.google.com/open?id=0B5Y65du7slVnZkVfaHJrSWtvd2c or https://docs.google.com/open?id=0B5Y65du7slVnWlB0b3BhNThzczA
avatar
eTo
Posts : 2
Join date : 2012-07-30

webdriver + python, how to check for presence of text on page? Empty Re: webdriver + python, how to check for presence of text on page?

Wed Aug 01, 2012 5:22 am
Actually i think there are no such functions in python webdriver... searched module it self for them and didn't find them :/
Thought there might be some workaround for that but i guess except launching java or code from other programming language there is no option to stay 100% in python. And since i'm newbie in python... then i guess i stick to rc server.
Thx for those tables though, they have already proven them self useful Smile
avatar
TankorSmash
Posts : 1
Join date : 2012-09-11

webdriver + python, how to check for presence of text on page? Empty Re: webdriver + python, how to check for presence of text on page?

Tue Sep 11, 2012 11:12 am
Hey dude, I found this page through google, and then later solved my problem. The solution is page_source attribute

Code:
from selenium import webdriver
br = webdriver.Ie()
br.get('google.com')
print br.page_source
Sponsored content

webdriver + python, how to check for presence of text on page? Empty Re: webdriver + python, how to check for presence of text on page?

Back to top
Permissions in this forum:
You cannot reply to topics in this forum