|  | 
 
 发表于 2023-2-13 08:47:25
|
显示全部楼层
   本楼为最佳答案 
| 教程安装的是旧版本,现在新版本确实只剩下这两个函数了,新版本的 by 就是通过 by 参数传进去的 
 
   
 
 >>> from selenium.webdriver.common.by import By>>> dir(By)
 ['CLASS_NAME', 'CSS_SELECTOR', 'ID', 'LINK_TEXT', 'NAME', 'PARTIAL_LINK_TEXT', 'TAG_NAME', 'XPATH', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
 >>>
 比如 find_element_by_xpath 在新版本中应该是这样的:
 
 复制代码from selenium.webdriver.common.by import By
el = web.find_element(By.XPATH, '//*[@id="changeCityBox"]/ul/li[1]/a')
 | 
 |