Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
141 views
in Technique[技术] by (71.8m points)

Why selenium not recognizing class in Python?

Selenium is not recognizing the class. I was trying to click an audio button on a website using selenium but it is not recognizing this class

class="jumbo--Z12Rgj4 buttonWrapper--x8uow audioBtn--1H6rCK"

Here is my code

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
options = webdriver.ChromeOptions() 
options.add_argument(r"user-data-dir=./c")

driver=webdriver.Chrome(executable_path=r"C:UsersUsersDesktopScrappingchromedriver.exe",options=options)
    
driver.get(r"https://www.xx------xx.com")
    
button5 = driver.find_element_by_class_name(r"jumbo--Z12Rgj4")
    
button5.click()

But selenium is throwing an exception

jumbo--Z12Rgj4

Exception:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".label--Z12LMR3"}
question from:https://stackoverflow.com/questions/65625726/why-selenium-not-recognizing-class-in-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you check again, there would be more than one class 'jumbo--Z12Rgj4', hence selenium is throwing exception. To make it more dynamic, better use xpath with "contains(@class,'jumbo--Z12Rgj4')", followed by another identifier to make the search unique.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...