使用Selenium Python使用复合类解析HTML内容 [英] Parsing the HTML content using compound class using selenium python

查看:80
本文介绍了使用Selenium Python使用复合类解析HTML内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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="{&quot;powerOn icon-ok-sign&quot;: titleArea.systemStatus.connection.value, &quot;powerOff icon-remove-sign&quot; : !titleArea.systemStatus.connection.value}"></div>

推荐答案

但是,如果我使用class ="powerOn icon-ok-sign",则会出现错误,不允许使用复合类名称

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

实际上硒不支持使用化合物类来定位元素名称.

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

You should try using on of then instead as :-

driver.find_element_by_class_name("powerOn")

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

或者是使用css_selector通过多个类名来查找同一元素的最佳方法:-

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")

参考链接:-

  • Compound class names are not supported error in WebDriver
  • How to avoid Compound Class name error in Page Object?

这篇关于使用Selenium Python使用复合类解析HTML内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆