关于xpath 定位问题

来源:3-4 网页交互之响应鼠标事件

weixin_慕UI7443657

2022-07-28 11:56:08

关于xpath 定位问题

问题描述:

通过xpath 在浏览器中定位到相关信息,但在代码中显示没有相关元素。

相关截图:

https://img.mukewang.com/climg/62e2078b09daaac619120828.jpg


https://img.mukewang.com/climg/62e208ca0927478519161018.jpg


相关代码:

#coding=utf-8

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import pymongo
from selenium.webdriver.common.by import By
# 等待用包
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from lxml import etree
from selenium.webdriver.common.action_chains import ActionChains

clinet = pymongo.MongoClient(host="localhost",port=27017,username=' ', password=' ')
url = 'https://cer.zjjs.edu.cn/cas/login?service=https%3A%2F%2Fmy.zjjs.edu.cn%2Fpersonal-center'
school_web = webdriver.Chrome()
school_web.maximize_window()
school_web.get(url)
WebDriverWait(school_web,5,0.5).until(EC.presence_of_element_located((By.ID, "username")))
print("开始输入用户名")
school_web.find_element('id','username').send_keys("   ")
# webdriver(content,5,0.5).until(EC.presence_of_element_located((By.ID, "ppassword")))
print("开始输入密码")
school_web.find_element('id', 'ppassword').send_keys("    ")
school_web.find_element_by_xpath("//button[@type='button']").click()
if WebDriverWait(school_web,5,0.5).until(EC.presence_of_element_located((By.CLASS_NAME, "user-info"))):
    print('登录成功')
school_web.find_element(by='xpath',value='//*[@id="header"]/div/div/div/ul/li[6]/a').click()
print('跳转教务管理系统')
school_web.find_element(by='xpath',value='//*[text()=" 信息查询"]')


写回答

1回答

时间,

2022-07-28

同学,你好!同学定位的标签可能并不是直接写在html中的代码,同学可以在页面中右击,选择"查看网页源代码",在源代码中看下是否可以找到对应的数据,若没有则可能是用其他方法返回的数据。

同学使用的是学校的网站,我这没有办法进行测试,需要同学自己尝试解决。建议同学使用常见的网站进行练习。

祝学习愉快!

0

0 学习 · 4469 问题

查看课程

相似问题