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

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

问题描述

我收到以下错误:

不允许使用复合类名称"

"Compound class names not permitted"

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

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>

我试图通过CSS路径找到元素,如下所示.但是此元素不可搜索.

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

这是链接中提供的解决方法 a>,但仍然没有成功.您的帮助将不胜感激.

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天全站免登陆