python - 为什么 selenium 不能识别 Python 中的类?
问题描述
Selenium 无法识别该类。我试图单击使用 selenium 的网站上的音频按钮,但它无法识别此类
class="jumbo--Z12Rgj4 buttonWrapper--x8uow audioBtn--1H6rCK"
这是我的代码
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:\Users\Users\Desktop\Scrapping\chromedriver.exe",options=options)
driver.get(r"https://www.xx------xx.com")
button5 = driver.find_element_by_class_name(r"jumbo--Z12Rgj4")
button5.click()
但是硒抛出了一个异常
巨无霸--Z12Rgj4
例外:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".label--Z12LMR3"}
解决方案
如果再次检查,将会有不止一个类'jumbo--Z12Rgj4',因此 selenium 会抛出异常。为了使其更具动态性,最好使用带有“contains(@class,'jumbo--Z12Rgj4')”的 xpath,后跟另一个标识符以使搜索唯一。
推荐阅读
- excel - Excel 两次显示名称
- reactjs - material-ui Drawer - findDOMNode 在 StrictMode 中已弃用
- python - Python 在 Linux 上获得空闲时间
- swift - SwiftUI:为什么我不能在一个 HStack 中有多个 TextField?
- python - 从 matlab 获取一组 3D 子图?
- java - ReplaceAll Regex:替换前更新组
- c++ - 我的随机数生成器出现问题,数字超出范围
- excel - 如何将表格和书签插入Word,每页一个
- javascript - 问题如何使用cheerio获取具有沙盒元素的iframe的src
- spyder - 如何将配色方案导入 Spyder 4?