1

I have tried to retrieve some data from url page via Selenium, but after running function driver.find_element_by_class_name() I have obtained error message: 'WebDriver' object has no attribute 'find_element_by_class_name' Maybe this function has been deprecated in new module updates, please give me a hint where to find documentation for new function instead of deprecated.

This is my code:

import pandas as pd
import time
import selenium 
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
import seaborn as sns
import os
import logging
######

PATH = 'C:/Program Files/chromedriver/chromedriver.exe'
options = Options()

driver = webdriver.Chrome(service = 
                          Service(PATH))
page_url = "https://witcher.fandom.com/wiki/Category:Characters_in_the_stories"
driver.get(page_url)
book_categories = driver.find_elements_by_class_name('category-page__member-link') 


AttributeError: 'WebDriver' object has no attribute 'find_elements_by_class_name'
------------
book_categories = driver.find_elements(By = 'class_name','category-page__member-link')

SyntaxError: positional argument follows keyword argument

I use chromedriver version 109.0.5414.74. Chrome version 109.0.5414.75.

Also I tried to use this code:

driver.find_elements(By.NAME, 'category-page__member-link),

but it also led to error:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="category-page__member-link"]"}.

Please, help me to find out reason of this error and how to resolve it.

  • Does this answer your question? [Selenium - Python - AttributeError: 'WebDriver' object has no attribute 'find\_element\_by\_name'](https://stackoverflow.com/questions/72773206/selenium-python-attributeerror-webdriver-object-has-no-attribute-find-el) – Prophet Jan 25 '23 at 21:44
  • While you're at it, also ensure you've installed the correct version of the webdriver. – Gautam Chettiar Jan 25 '23 at 21:48

1 Answers1

1

Your locator is correct, but your locator type is wrong. 'category-page__member-link' is the value of class attribute not name, so you have to mention like:

driver.find_element(By.CLASS_NAME, "category-page__member-link")

or

driver.find_element(By.CSS_SELECTOR, ".category-page__member-link")
AbiSaran
  • 2,538
  • 3
  • 9
  • 15
  • Thank you for a hint. Now I can scrap the data, but why I still can't obtain the same output by the . Is this function deprecated isn't it? And where I can find the documentation where says it? Thank you for answer. – Olga Klishchuk Jan 27 '23 at 14:04