不允许复合类名错误 Webdriver [英] Compound class names not permitted error Webdriver

查看:17
本文介绍了不允许复合类名错误 Webdriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误:

<块引用>

不允许使用复合类名"

尝试访问 web 元素时,其中元素的类名之间有空格.网页元素的页面来源如下.

driver.findElement(By.className("alert alert-success"));

<div class="alert alert-success" alert-dismissable"="" id="58417" style="display: none;"><button type="button" class="close hide-panel close-icon-58417" data-dismiss="alert" aria-hidden="true" style="display: inline-block;">×</button><span id="caret-58417" class="notification-caret caret-58417"></span><div class="hide-panel close-icon-58417" id="58417" style="display: block;"><span class="glyphicon glyphicon-ok-sign"></span><strong>成功</strong>KeyLinks 更新成功<div class="notification-panel-body panel-body-58417">REST 调用成功</div>

我尝试通过 CSS 路径查找元素,如下所示.但是这个元素是不可搜索的.

driver.findElement(By.cssSelector(".alert alert-success"));

这是链接中给出的解决方法 但仍然没有成功.您的帮助将不胜感激.

解决方案

如果元素有多个类,您可以使用By"访问它:

from selenium.webdriver.common.by import Bydriver.findElement(By.cssSelector(".alert.alert-success"));

I am getting the following error:

"Compound class names not permitted"

While trying to access web element where-in the element's class name have spaces in between. The page source for the web element is as below.

driver.findElement(By.className("alert alert-success"));

<div class="alert alert-success" alert-dismissable"="" id="58417" style="display: none;">
   <button type="button" class="close hide-panel close-icon-58417" data-dismiss="alert" aria-hidden="true" style="display: inline-block;">×</button><span id="caret-58417" class="notification-caret caret-58417"></span>
   <div class="hide-panel close-icon-58417" id="58417" style="display: block;">
      <span class="glyphicon glyphicon-ok-sign"></span><strong>Success</strong> KeyLinks Updated Successfully
      <div class="notification-panel-body panel-body-58417">REST Invocation Success</div>
   </div>
</div>

I tried to find the element by CSS path as below. But the element is not searchable with this.

driver.findElement(By.cssSelector(".alert alert-success"));

This was the workaround given in the Link but still no success. your help will be much appreciated.

解决方案

You can access the element if it has multiple classes using "By":

from selenium.webdriver.common.by import By
driver.findElement(By.cssSelector(".alert.alert-success"));

这篇关于不允许复合类名错误 Webdriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆