- eTo
- Posts : 2
Join date : 2012-07-30
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?
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?
- Sagot
- Posts : 4
Join date : 2012-07-05
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
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
- eTo
- Posts : 2
Join date : 2012-07-30
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
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
- TankorSmash
- Posts : 1
Join date : 2012-09-11
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
- How to check the whether the text present in the page or under particular area or not in Webdriver
- How to verify particular TEXT color in web page using selenium webdriver?
- How to get the tittle of a object (not window), bcz title holds the full text but inner text holds only 25 char of text (in RC and Webdriver)
- Verify text present when the text appears in more location in the page
- I am having trouble verifying text on the web page
Permissions in this forum:
You cannot reply to topics in this forum