Search
 
 

Display results as :
 


Rechercher Advanced Search

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

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

View previous topic View next topic Go down

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

Post by eTo on 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?

eTo

Posts : 2
Join date : 2012-07-30

Back to top Go down

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

Post by Sagot on 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

Sagot

Posts : 4
Join date : 2012-07-05

Back to top Go down

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

Post by eTo on 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

eTo

Posts : 2
Join date : 2012-07-30

Back to top Go down

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

Post by TankorSmash on 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

TankorSmash

Posts : 1
Join date : 2012-09-11

Back to top Go down

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

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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