Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Selenium by (7k points)
edited by

I tried to pull a table from wikipedia. The following used is not working.

driver.find_element_by_class_name(name)

However when going to the html source code I see the class name which I am looking for.I do realize there are other ways to pull this table and I have moved on to easier ways. Why Selenium does not find class when it is written in HTML. 

from selenium import webdriver

driver = webdriver.Chrome(r"\chromedriver_win32\chromedriver.exe")

driver.get(r'https://en.wikipedia.org/wiki/List_of_airports_in_the_United_States')

driver.implicitly_wait(2)

driver.find_element_by_class_name(name='wikitable sortable jquery-tablesorter')

The error I get is

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".wikitable sortable jquery-tablesorter"}

1 Answer

0 votes
by (31.9k points)

Use CSS selector to use all three classes in a single locator.

Example:

.wikitable.sortable.jquery-tablesorter

Want to learn Selenium, checkout our Selenium training.

Browse Categories

...