Selenium python find_element_by_class_name() 从 v 2.2 到 2.21 停止工作——不能使用“复合类名"

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 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 停止工作——不能使用“复合类名"

基础教程推荐