问题
I am having a display button in my GUI that shows the connection status (Button with Green check means connection is established and with Red cross means no connection) I have to check the status using my code. I am parsing the content of that particular title-bar class name (container-fluid). And from this, I am parsing the explicit content of that display button.
elem = driver.find_element_by_class_name("container-fluid")
a= elem.get_attribute("outerHTML")
b= a.split("powerOn icon-ok-sign")
After this, I parse some explicit content of that button and decide that connection is there or not.
But If I use class="powerOn icon-ok-sign", I get error :
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>
回答1:
But If I use class="powerOn icon-ok-sign", I get error Compound class names not permitted
Actually selenium doesn't support to locate an element using Compound class name.
You should try using on of then instead as :-
driver.find_element_by_class_name("powerOn")
Or
driver.find_element_by_class_name("icon-ok-sign")
Or best way to use css_selector
to locate same element using multiple class name as :-
driver.find_element_by_css_selector(".powerOn.icon-ok-sign")
Reference link :-
- Compound class names are not supported error in WebDriver
- How to avoid Compound Class name error in Page Object?
回答2:
You can use search by CSS Selector
instead:
driver.find_element_by_css_selector(".powerOn.icon-ok-sign")
or use one of class names to select your element:
driver.find_element_by_class_name("powerOn")
来源:https://stackoverflow.com/questions/41633896/parsing-the-html-content-using-compound-class-using-selenium-python