- 前言
- 由于web页面元素class属性值带有空格,导致直接使用class属性值元素定位失败
- 如: class=“inputstyle password” ,直接使用定位:driver.find_element_by_class_name(“inputstyle password”).send_keys(“1111”)
- **html classname值描述: **规定元素的类的名称。如需为一个元素规定多个类,用空格分隔类名。
- W3cschool 对于class属性介绍
- 报错日志
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {
"method":"css selector","selector":".inputstyle password"}
(Session info: chrome=81.0.4044.138)
-
示例:QQ邮箱 - 账号/密码输入框
-
账号输入框:class = inputstyle
-
密码输入框:class = inputstyle password
-
-
解决办法
- 方法一:driver.find_element_by_class_name方式定位
- 控件class值包含多个类,可使用任意单个唯一类型来定位,如:inputstyle、password
- 但是由于账号输入框class属性值为inputstyle&#x
- 方法一:driver.find_element_by_class_name方式定位