代码改变世界

python查找时,不支持compound class

2015-12-29 16:39  sophia194910  阅读(440)  评论(0编辑  收藏  举报

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来进行查找即可。