본문 바로가기

Language

[Selenium Python] 'WebDriver' object has no attribute 'find_elements_by_class_name'

728x90

문제점

Chrome 115 버전 이슈를 해결하기 위해 Selenium을 3버전대에서 4버전으로 올린 뒤 WebDriver에서 find_elements_by_class_name 속성을 못찾는 현상이 발생했습니다.

...
AttributeError: 'WebDriver' object has no attribute 'find_elements_by_class_name'

원인

Selenium이 3.x에서 4.x로 변경되면서 find_element, find_elements로 통합되었습니다.

기존 find_element(s)_by 함수는 deprecated 되었습니다.

해결방법

아래와 같이 함수를 변경하면 됩니다.

web_driver.find_element(By.ID, "id")

web_driver.find_element(By.NAME, "name")

web_driver.find_element(By.XPATH, "xpath")

web_driver.find_element(By.LINK_TEXT, "link text")

web_driver.find_element(By.PARTIAL_LINK_TEXT, "partial link text")

web_driver.find_element(By.TAG_NAME, "tag name")

web_driver.find_element(By.CLASS_NAME, "class name")

web_driver.find_element(By.CSS_SELECTOR, "css selector")

매칭되는 다수의 element를 검색하려면 find_elements를 사용하시면 됩니다.

반응형