之前用Python写过一个校园网自动连接的脚本,链接如下
南京邮电大学—校园网(NJUPT-CMCC)自动连接脚本—基于Python
代码原本使用webdriver对象的 find_element_by_xpath方法来定位输入框并发送消息,但是在selenium的4.0版本中此种用法已经被抛弃,故而会报这样的错误
‘WebDriver’ object has no attribute ‘find_element_by_xpath’
如果仍然想使用xpath定位元素的话,需要做如下修改:
- 导入模块
from selenium.webdriver.common.by import By
- 将原本的
driver.find_element_by_xpath('******').send_keys('******')
改为
driver.find_element(By.XPATH, '******').send_keys('******')