python查找时,不支持compound class

1.python使用如下代码查找页面上的元素时,

browser.findElement_by_class_name("widget-content nopadding")

报错:

selenium.common.exceptions.WebDriverException: Message: u'Compound class names not permitted'

python不支持类名中间带有空格,上述类名会被当做2个处理,因此会报错。

2.解决方法如下:

browser.find_element_by_css_selector(".widget-content.nopadding")

改用css selector来进行查找即可。

你可能感兴趣的:(python查找时,不支持compound class)