我收到以下错误:
"Compound class names not permitted"
尝试访问Web元素时,元素的类名之间存在空格。 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>Success</strong> KeyLinks Updated Successfully
<div class="notification-panel-body panel-body-58417">REST Invocation Success</div>
</div>
</div>
我试图通过CSS路径找到元素,如下所示。但是,此元素不可搜索。
driver.findElement(By.cssSelector(".alert alert-success"));
这是解决方法given in the Link,但仍然没有成功。您的帮助将不胜感激。
最佳答案
如果元素具有多个类,则可以使用“按”来访问该元素:
from selenium.webdriver.common.by import By
driver.findElement(By.cssSelector(".alert.alert-success"));
关于selenium-webdriver - 不允许的复合类名称错误Webdriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32043877/