求助老师 用 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()

相关截图:

https://img.mukewang.com/climg/62973efe09cc871717230562.jpg

写回答

1回答

时间,

2022-06-01

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

https://img.mukewang.com/climg/629742b309dd035f20240553.jpg

祝学习愉快!

0

0 学习 · 4470 问题

查看课程