我的 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")
引用链接:-
