我的 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="{"powerOn icon-ok-sign": titleArea.systemStatus.connection.value, "powerOff icon-remove-sign" : !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/