开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 964|回复: 4
收起左侧

[已解决] xpath 相对路径定位取值求助

 关闭 [复制链接]
结帖率:94% (80/85)
发表于 2022-7-7 20:30:30 | 显示全部楼层 |阅读模式   重庆市重庆市
50精币
一、取出:[栏目标识] 下,有:修改按钮 的 第二项名称。
二、然后点击:[栏目标识] 下 第二项名称 后的:修改按钮


xpath 相对路径定位取值求助

代码如下:
<tr role="row" id="29" tabindex="-1" class="jqgrow" data-level="0" aria-level="0" aria-expanded="true"><td role="gridcell" style="white-space:nowrap;display:none;" title="29" aria-describedby="ui-id-23_id" aria-labelledby="jqh_ui-id-23_id">29</td><td role="gridcell" style="white-space:nowrap;" title="[栏目标识]" aria-describedby="ui-id-23_offerName" aria-labelledby="jqh_ui-id-23_offerName"><div class="tree-wrap" style="width:18px;"><div style="margin-left:0px;" class="treeclick glyphicon glyphicon-triangle-bottom tree-minus"></div></div><span class="cell-wrapper"><b><span class="js-shouDetailed" searchvalue="undefined">[栏目标识]</span></b></span></td><td role="gridcell" style="white-space:nowrap;" title="" aria-describedby="ui-id-23_accNbr" aria-labelledby="jqh_ui-id-23_accNbr"><span class="js-accNbr"></span></td><td role="gridcell" style="white-space:nowrap;" title="" aria-describedby="ui-id-23_acctCd" aria-labelledby="jqh_ui-id-23_acctCd"> </td><td role="gridcell" style="white-space:nowrap;" title="" aria-describedby="ui-id-23_effDate" aria-labelledby="jqh_ui-id-23_effDate"> </td><td role="gridcell" style="white-space:nowrap;" title="" aria-describedby="ui-id-23_expDate" aria-labelledby="jqh_ui-id-23_expDate"> </td><td role="gridcell" style="white-space:nowrap;display:none;" title="" aria-describedby="ui-id-23_ext_offer_inst_id" aria-labelledby="jqh_ui-id-23_ext_offer_inst_id"> </td><td role="gridcell" style="white-space:nowrap;display:none;" title="" aria-describedby="ui-id-23_manage_grade" aria-labelledby="jqh_ui-id-23_manage_grade"> </td><td role="gridcell" style="white-space:nowrap;display:none;" title="" aria-describedby="ui-id-23_main_flag" aria-labelledby="jqh_ui-id-23_main_flag"> </td><td role="gridcell" style="white-space:nowrap;" aria-describedby="ui-id-23_speed" aria-labelledby="jqh_ui-id-23_speed"></td><td role="gridcell" style="white-space:nowrap;" title="" aria-describedby="ui-id-23_stopType" aria-labelledby="jqh_ui-id-23_stopType"><span class="label label-line-danger"></span></td><td role="gridcell" style="white-space:nowrap;display:none;" title="" aria-describedby="ui-id-23_replySmallClass" aria-labelledby="jqh_ui-id-23_replySmallClass"> </td><td role="gridcell" style="white-space:nowrap;" title="" aria-describedby="ui-id-23_measureId" aria-labelledby="jqh_ui-id-23_measureId"> </td><td role="gridcell" style="white-space:nowrap;" aria-describedby="ui-id-23_操作" aria-labelledby="jqh_ui-id-23_操作"></td></tr>
<tr role="row" id="30" tabindex="-1" class="jqgrow" data-level="1" aria-level="1" aria-expanded="true" style=""><td role="gridcell" style="white-space:nowrap;display:none;" title="30" aria-describedby="ui-id-23_id" aria-labelledby="jqh_ui-id-23_id">30</td><td role="gridcell" style="white-space:nowrap;" title="第一项名称" aria-describedby="ui-id-23_offerName" aria-labelledby="jqh_ui-id-23_offerName"><span class="ui-treeline-first"></span><div class="tree-wrap" style="width: 0px;"><div style="margin-left: 0px;" class=" tree-leaf "></div></div><span class="cell-wrapper leaf"><b><span class="js-shouDetailed" searchvalue="undefined">第一项名称</span></b></span></td><td role="gridcell" style="white-space:nowrap;" title="" aria-describedby="ui-id-23_accNbr" aria-labelledby="jqh_ui-id-23_accNbr"><span class="js-accNbr"></span></td><td role="gridcell" style="white-space:nowrap;" title="11111" aria-describedby="ui-id-23_acctCd" aria-labelledby="jqh_ui-id-23_acctCd">11111</td><td role="gridcell" style="white-space:nowrap;" title="2021-01-01 00:00:00" aria-describedby="ui-id-23_effDate" aria-labelledby="jqh_ui-id-23_effDate">2021-01-01 00:00:00</td><td role="gridcell" style="white-space:nowrap;" title="2038-12-31 23:59:59" aria-describedby="ui-id-23_expDate" aria-labelledby="jqh_ui-id-23_expDate">2038-12-31 23:59:59</td><td role="gridcell" style="white-space:nowrap;display:none;" title="" aria-describedby="ui-id-23_ext_offer_inst_id" aria-labelledby="jqh_ui-id-23_ext_offer_inst_id"> </td><td role="gridcell" style="white-space:nowrap;display:none;" title="" aria-describedby="ui-id-23_manage_grade" aria-labelledby="jqh_ui-id-23_manage_grade"> </td><td role="gridcell" style="white-space:nowrap;display:none;" title="" aria-describedby="ui-id-23_main_flag" aria-labelledby="jqh_ui-id-23_main_flag"> </td><td role="gridcell" style="white-space:nowrap;" aria-describedby="ui-id-23_speed" aria-labelledby="jqh_ui-id-23_speed"></td><td role="gridcell" style="white-space:nowrap;" title="" aria-describedby="ui-id-23_stopType" aria-labelledby="jqh_ui-id-23_stopType"><span class="label label-line-danger"></span></td><td role="gridcell" style="white-space:nowrap;display:none;" title="" aria-describedby="ui-id-23_replySmallClass" aria-labelledby="jqh_ui-id-23_replySmallClass"> </td><td role="gridcell" style="white-space:nowrap;" title="正正正正" aria-describedby="ui-id-23_measureId" aria-labelledby="jqh_ui-id-23_measureId">正正正正</td><td role="gridcell" style="white-space:nowrap;" title="修改按钮" aria-describedby="ui-id-23_操作" aria-labelledby="jqh_ui-id-23_操作"><button type="button" class="btn btn-primary js-change" data-reg-id="00000000" name="RECEPTION_LOCATION_CHANGE_BUTTON">修改按钮</button></td></tr>
<tr role="row" id="31" tabindex="-1" class="jqgrow" data-level="1" aria-level="1" aria-expanded="true" style=""><td role="gridcell" style="white-space:nowrap;display:none;" title="31" aria-describedby="ui-id-23_id" aria-labelledby="jqh_ui-id-23_id">31</td><td role="gridcell" style="white-space:nowrap;" title="第二项名称" aria-describedby="ui-id-23_offerName" aria-labelledby="jqh_ui-id-23_offerName"><span class="ui-treeline-first"></span><div class="tree-wrap" style="width: 0px;"><div style="margin-left: 0px;" class=" tree-leaf "></div></div><span class="cell-wrapper leaf"><b><span class="js-shouDetailed" searchvalue="undefined">第二项名称</span></b></span></td><td role="gridcell" style="white-space:nowrap;" title="" aria-describedby="ui-id-23_accNbr" aria-labelledby="jqh_ui-id-23_accNbr"><span class="js-accNbr"></span></td><td role="gridcell" style="white-space:nowrap;" title="11111" aria-describedby="ui-id-23_acctCd" aria-labelledby="jqh_ui-id-23_acctCd">11111</td><td role="gridcell" style="white-space:nowrap;" title="2021-01-01 00:00:00" aria-describedby="ui-id-23_effDate" aria-labelledby="jqh_ui-id-23_effDate">2021-01-01 00:00:00</td><td role="gridcell" style="white-space:nowrap;" title="2039-12-31 23:59:59" aria-describedby="ui-id-23_expDate" aria-labelledby="jqh_ui-id-23_expDate">2039-12-31 23:59:59</td><td role="gridcell" style="white-space:nowrap;display:none;" title="" aria-describedby="ui-id-23_ext_offer_inst_id" aria-labelledby="jqh_ui-id-23_ext_offer_inst_id"> </td><td role="gridcell" style="white-space:nowrap;display:none;" title="" aria-describedby="ui-id-23_manage_grade" aria-labelledby="jqh_ui-id-23_manage_grade"> </td><td role="gridcell" style="white-space:nowrap;display:none;" title="" aria-describedby="ui-id-23_main_flag" aria-labelledby="jqh_ui-id-23_main_flag"> </td><td role="gridcell" style="white-space:nowrap;" aria-describedby="ui-id-23_speed" aria-labelledby="jqh_ui-id-23_speed"></td><td role="gridcell" style="white-space:nowrap;" title="" aria-describedby="ui-id-23_stopType" aria-labelledby="jqh_ui-id-23_stopType"><span class="label label-line-danger"></span></td><td role="gridcell" style="white-space:nowrap;display:none;" title="" aria-describedby="ui-id-23_replySmallClass" aria-labelledby="jqh_ui-id-23_replySmallClass"> </td><td role="gridcell" style="white-space:nowrap;" title="正正正正" aria-describedby="ui-id-23_measureId" aria-labelledby="jqh_ui-id-23_measureId">正正正正</td><td role="gridcell" style="white-space:nowrap;" title="修改按钮" aria-describedby="ui-id-23_操作" aria-labelledby="jqh_ui-id-23_操作"><button type="button" class="btn btn-primary js-change" data-reg-id="00000000" name="RECEPTION_LOCATION_CHANGE_BUTTON">修改按钮</button></td></tr>

最佳答案

查看完整内容

其实,你用如果用谷歌,你在当前元素上面,右键(检查),然后在开发工具的当前元素,再右键(COPY/复制),就有XPATH的全路径,或者相对路径,我自己就是这么用废了的

回答提醒:如果本帖被关闭无法回复,您有更好的答案帮助楼主解决,请发表至 源码区 可获得加分喔。
友情提醒:本版被采纳的主题可在 申请荣誉值 页面申请荣誉值,获得 1点 荣誉值,荣誉值可兑换荣誉会员、终身vip用户组。
快捷通道:申请荣誉值无答案申请取消悬赏投诉有答案未采纳为最佳
结帖率:92% (12/13)

签到天数: 25 天

发表于 2022-7-7 20:30:31 | 显示全部楼层   广东省江门市
其实,你用如果用谷歌,你在当前元素上面,右键(检查),然后在开发工具的当前元素,再右键(COPY/复制),就有XPATH的全路径,或者相对路径,我自己就是这么用废了的

评分

参与人数 1荣誉 +1 收起 理由
笨潴 + 1 热心帮助他人,荣誉+1,希望继续努力(*^__^*) 嘻嘻!

查看全部评分

回复

使用道具 举报

结帖率:100% (9/9)

签到天数: 10 天

发表于 2022-7-7 21:49:16 | 显示全部楼层   内蒙古自治区*
element_1 = document.evaluate("//td[@title='修改按钮']/preceding::td[@title='第二项名称']",document).iterateNext();
element_2 = document.evaluate("./following::td[@title='修改按钮']/button",element_1).iterateNext().click();

补充内容 (2022-7-7 21:51):
没注意是python,我还以为是js..sorry...   直接拿中间的xpath用就好了.一样的

评分

参与人数 1精币 +2 收起 理由
Z隐 + 2 感谢帮助

查看全部评分

回复

使用道具 举报

结帖率:94% (80/85)

签到天数: 25 天

 楼主| 发表于 2022-10-7 02:53:28 | 显示全部楼层   重庆市重庆市
q549713289 发表于 2022-10-6 00:39
其实,你用如果用谷歌,你在当前元素上面,右键(检查),然后在开发工具的当前元素,再右键(COPY/复制) ...

请教:右键:取:相对路径,是哪个选项?我取出来的看着都是全路径。。。
回复

使用道具 举报

结帖率:92% (12/13)

签到天数: 25 天

发表于 2022-12-4 16:44:07 | 显示全部楼层   广东省江门市
Z隐 发表于 2022-10-7 02:53
请教:右键:取:相对路径,是哪个选项?我取出来的看着都是全路径。。。 ...

[复制xpath] 就是相对路径
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 诚聘英才| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 800073686,邮箱:800073686@b.qq.com
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表