求助老师 用 LINK_TEXT报错 用xpath语句则运行正常 这是为啥?
来源:3-4 网页交互之响应鼠标事件
_WHOAMI_
2022-06-01 18:27:39
# coding:utf-8
import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
web = webdriver.Chrome()
web.maximize_window()
web.get('https://www.baidu.com')
# 通过xpath语句定位到页面的'设置' 并赋值给变量above
above = web.find_element(By.LINK_TEXT, '设置')
# above = web.find_element(By.XPATH, '//span[@name="tj_settingicon"]')
# 执行操作
ActionChains(web).move_to_element(above).perform()
time.sleep(5)
web.quit()相关截图:

1回答
同学,你好!LINK_TEXT是通过超文本链接上的文字信息来定位元素,而"设置"对应的是span标签并不超文本链接,所以会报错

祝学习愉快!
相似问题