Webdriver byclassname error:"Compound class names not permitted


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

当class的属性值,中间有空格时,通过by方法会报错:Compound class names not permitted


You can access the element if it has multiple classes like below:


You can use

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

As right now selenium doesn't support multiple class name.If your class name includes a space, WebDriver will see it as a "compound selector". You can use cssSelector or id for selecting the webelement.

1down vote

If usage of class name is must you can use the following ways:

1) css selectors:


2) using xpath

driver.findElement(By.xpath("//div[@class='alert alert-success']"))

Try avoiding xpath and use css selectors instead.

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页