当我try 使用find_element(By.CLASS_NAME, 'classname')
时,它总是返回NoSuchElementException,找不到元素.
但是,当我在同一个元素上使用ID和名称时,它起作用了!只有CLASS_NAME失败.
Here is the HTML个
<input type="text" name="login" id="login_field" class="form-control input-block js-login-field" autocapitalize="off" autocorrect="off" autocomplete="username" autofocus="autofocus">
And here is the script个
username1 = driver.find_element(By.CLASS_NAME,"form-control input-block js-login-field")
username2 = driver.find_element(By.ID,"login_field")
print(username1)
print(username2)
用户名%1失败,用户名%2通过.
我try 更改为css Selector:
username1 = driver.findElement(By.cssSelector("input.form-control input-block js-login-field"));
个
我还try 了更改语法:
username1 = driver.find_element(By.CLASS_NAME("input[class='form-control input-block js-login-field']"))
但这些都不管用.