selenium_user
selenium_user

Reputation: 79

How to create Selenium objects?

I want to use following functions: get_xpath_count() get_css_count() and others available on http://selenium.googlecode.com/git/docs/api/py/_modules/selenium/selenium.html#selenium.get_xpath_count with selenium object.

But I am not able to create a selenium object to use these functions? Can anyone help?

Upvotes: 1

Views: 127

Answers (1)

alecxe
alecxe

Reputation: 473803

You are mixing selenium web driver API and Selenium 1 / Selenium RC API: what's the relationship between Selenium RC and WebDriver? is worth reading.

get_xpath_count() and get_css_count() are not a part of selenium WebDriver API.

You can actually simulate get_xpath_count() by calling len() on find_elements_by_xpath() method:

from selenium import webdriver


driver = webdriver.Firefox()
driver.get("https://en.wikipedia.org")

print len(driver.find_elements_by_xpath('//li'))

get_css_count() could be implemented like this:

print len(driver.find_elements_by_tag_name('li'))

Hope that helps.

Upvotes: 1

Related Questions