Webdriver byclassname error:"Compound class names not permitted

原文地址:https://www.douban.com/note/637775924/

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:

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

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:

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

2) using xpath

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

Try avoiding xpath and use css selectors instead.

你可能感兴趣的:(Selenium,+,Python)