Selenium Webdriver With Python
Basic Example
Verifying Table Values
#Importing selenium webdriver library
#Iterating over the table data using xpath to verify the price
Selecting element from drop down listel = driver.find_element_by_id( 'id_line' ) for option in el.find_elements_by_tag_name( 'option' ): if option.text = = "line to select" : option.click() break |
Verifying Table Values
#Importing selenium webdriver library
from selenium import webdriver
#Creating an driver instance of Firefox browser
driver = webdriver.Firefox()#Accessing the Flipkart site url for the python book
#creating an array object named data
driver.get("http://www.flipkart.com/programming-python-4th-e-d/p/itmczzj4gpfrr6bs?pid=9789350232873&icmpid=reco_pp_hSame_book_1")
data=[]
#Iterating over the table data using xpath to verify the price
for tr in driver.find_elements_by_xpath('//table[@class="mprod-similar-prod-table"]//tr'):
tds=tr.find_elements_by_tag_name('td')
if tds:
data= [td.text for td in tds]
print "3730" in data[2] #or whatever is the current price
Comments