selenium学习笔记(9)——Message: invalid selector: Compound class names not permitted 遇到class名称的tag,该如何处理?

想要系统学习python selenium自动化测试,请关注我的专栏: https://blog.csdn.net/column/details/29112.html 

环境:python3.6 + selenium 3.11 +  chromedriver.exe

我们在解析网页的时候,总是会遇到大量的tag,如何精确定位到这些tag,也是有很多的方法。

今天在用 find_element_by_class_name获取一个节点对象时,报了个错 Compound class names not permitted.

需要解析的页面结构:

原始代码:

driver.find_element_by_class_name('inputstyle password').send_keys('shdsifkjds55')

结果报错:

修改后代码:

driver.find_element_by_css_selector('.inputstyle.password').send_keys('shdsifkjds55') 

或者:

driver.find_element_by_css_selector("[class='inputstyle password']").send_keys('shdsifkjds55')

总结:

在获取包含多个class名称的tag对象时,如:class="inputstyle password",(中间有空格),建议使用:

find_element_by_css_selector(".xx.xxx.xxxxx")

或者

find_element_by_css_selector("[class='xx xxx xxxxx']")

本博文参考    https://blog.csdn.net/fengqiaoxian/article/details/81101844   


 

猜你喜欢

转载自blog.csdn.net/huang1600301017/article/details/83834566