Selenium python find_element_by_class_name() stopped working from v 2.2 to 2.21 -- cannot use #39;Compound Class Name#39;(Selenium python find_element_by_class_name() 从 v 2.2 到 2.21 停止工作——不能使用“复合类名)
问题描述
我正在使用 Selenium 的 python 库从 Firefox 的 html 页面中抓取数据.
I am using Selenium's python library to scrape data from a html page in Firefox.
我不得不从 Selenium 2.0 更新到 2.21,因为服务器已经更新了 Firefox.
I have had to update from Selenium 2.0 to 2.21 because the server has updated Firefox.
在 v 2.21 中,调用 find_element_by_class_name("grid-cell-inner grid-col-name")
失败并显示:
In v 2.21 calls to find_element_by_class_name("grid-cell-inner grid-col-name")
fails with:
selenium.common.exceptions.WebDriverException: Message: u'Compound class names not permitted'
我试图访问的元素的类名是 grid-cell-inner grid-col-name
The class name of the element I am trying to access is grid-cell-inner grid-col-name
find_element_by_class_name()
的调用在 v 2.2 中有效,所以逻辑是正确的,并且以前可以找到数据.v 2.21 中发生了一些变化.
The call to find_element_by_class_name()
worked in v 2.2, so the logic is correct, and the data used to be found OK. Something changed in v 2.21.
所有 Selenium 示例都给出了类名称为 foo
等的简单示例,没有我需要访问的名称类型.
All the Selenium examples give simple examples with class name foo
etc, and none with the type of name I need to access.
为什么 Selenium 停止支持查找名称为 grid-cell inner grid-col-name
的类,以及他们的解决方案是什么?
Why did Selenium stop supporting finding classes with names like grid-cell inner grid-col-name
, and what it their solution?
有人可以帮我找到复合"的元素吗?类名?
Can someone please help me to find elements with "compound" class names?
推荐答案
WebDriver 的问题是它还在进化.很多.我个人不知道有哪个版本支持在一个命令中搜索多个类,所以它一定是一个相当古老的版本:).
The problem about WebDriver is that it still evolves. A lot. I personally don't know about a version that supported searching by many classes in one command, so it must have been a fairly old one :).
通过 CSS 选择器 搜索应该可以,但是:
Searching by a CSS selector should work, however:
find_element_by_css_selector(".grid-cell-inner.grid-col-name");
我不建议对这个特定的东西使用 XPath,因为下面这两个表达式是另一回事:
I don't recommend using XPath for this particular thing, because these two following expressions are a different thing:
//*[class='grid-cell-inner grid-col-name']
//*[class='grid-col-name grid-cell-inner']
这篇关于Selenium python find_element_by_class_name() 从 v 2.2 到 2.21 停止工作——不能使用“复合类名"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Selenium python find_element_by_class_name() 从 v 2.2 到 2.21 停止工作——不能使用“复合类名"


基础教程推荐
- 修改列表中的数据帧不起作用 2022-01-01
- 包装空间模型 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01