python - 使用 selenium python 使用复合类解析 HTML 内容

标签 python selenium selenium-webdriver css-selectors classname

我的 GUI 中有一个显示按钮,用于显示连接状态(带有绿色勾号的按钮表示已建立连接,带有红色叉号的按钮表示没有连接) 我必须使用我的代码检查状态。 我正在解析该特定标题栏类名(容器流体)的内容。 由此,我正在解析该显示按钮的显式内容。

elem = driver.find_element_by_class_name("container-fluid")
a= elem.get_attribute("outerHTML")
b= a.split("powerOn icon-ok-sign") 

此后,我解析该按钮的一些显式内容并确定连接是否存在。

但是如果我使用class="powerOn icon-ok-sign",我会收到错误:

Compound class names not permitted

<div class="powerOn icon-ok-sign" data-original-title="Connection" style=" font-size: 2em;" data-toggle="tooltip" title="" data-placement="bottom" ng-class="{&quot;powerOn icon-ok-sign&quot;: titleArea.systemStatus.connection.value, &quot;powerOff icon-remove-sign&quot; : !titleArea.systemStatus.connection.value}"></div>

最佳答案

But If I use class="powerOn icon-ok-sign", I get error Compound class names not permitted

实际上selenium doesn't support to locate an element using Compound class姓名。

您应该尝试使用 on of then 来代替:-

driver.find_element_by_class_name("powerOn")

或者

driver.find_element_by_class_name("icon-ok-sign")

或者使用css_selector使用多个类名来定位相同元素的最佳方法:-

driver.find_element_by_css_selector(".powerOn.icon-ok-sign")

引用链接:-

关于python - 使用 selenium python 使用复合类解析 HTML 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41633896/

相关文章:

python - 我的 Keras 模型不预测负值

python - Django Admin 一次编辑多个模型

java - 为什么我的所有页面数据都显示 StaleElementReferenceException

java - Selenium WebDriver 中的自定义隐式等待加载页面消失

Python 使用 Selenium 和 Beautiful Soup 抓取 JavaScript

javascript - 使用 Javascript 从 Selenium::Remote::Driver 包恢复 Windows "Confirm Box"

python - 如何将 Python 的 itertools.product 库从列表理解转换为普通的 for 循环?

java - Selenium Java 代码打印 google 搜索的前五个结果

java - Selenium Select - 通过部分文本选择下拉选项

python - Flash视频录制网站教程