gpt4 book ai didi

以 X 开头并以零或最小数字结尾的 Python XPath

转载 作者:行者123 更新时间:2023-12-01 01:32:08 28 4
gpt4 key购买 nike

如果有人能帮助我编写实现以下目标的 XPath,我将非常感激:

  • 查找具有以下 id 的元素:“revit_form_Button_50”,其中数字不断变化(可能是 30/40,但页面上的第一个似乎总是以 0 结尾),并且标题还为“每日技术总计/”每日技术总计/员工每日总计报告”
  • 或查找如下元素:“revit_form_Button_”+“minnumnumber”并包含图 block :“每日技术总计/每日技术总计/员工每日总计报告”

任何方法都会对我有很大帮助。

我的前两次失败的尝试:

browser.find_element_by_xpath("//*[starts-with(@id,'revit_form_Button_' ) and ends-with(@id,'0')]").click()

browser.find_element_by_xpath("//*[boolean(number(substring-before(substring-after(@id, 'revit_form_Button_'), '0')))]").click()

enter image description here

<div id="reporting_grid_CellReportTitle_10" class="rptCellReportTitle" widgetid="reporting_grid_CellReportTitle_10">
<div dojoattachpoint="divReportTitle" class="rptCellReportTitleSpanNode"><span class="dijit dijitInline dijitReset revitButtonHideBackground revitButton" data-dojo-attach-point="focusNode,titleNode,stateNode" role="button" aria-labelledby="revit_form_Button_30_label" data-dojo-attach-event="ondijitclick:_onClick" tabindex="0" id="revit_form_Button_30" widgetid="revit_form_Button_30" style="position: relative; user-select: none;">
<span class="dijitReset revitIconNode dijitNoIcon" data-dojo-attach-point="iconNode" style="display: none;"></span>
<span class="dijitReset dijitButtonText" id="revit_form_Button_30_label" data-dojo-attach-point="containerNode" style="padding-left: 0px; text-transform: none;"><b>Daily Tech Totals / Daily Tech Totals / Employee Daily Totals Report</b></span>
<span class="dijitReset revitIconNode revitIconRightNode dijitNoIcon" data-dojo-attach-point="iconRightNode"></span>
<input type="button" value="" class="dijitOffScreen" tabindex="-1" role="presentation" data-dojo-attach-point="valueNode">
</span></div>
<div dojoattachpoint="divNotes" class="rptCellReportTitleNotesNode"></div>
<div dojoattachpoint="divSchedule" class="rptCellReportTitleScheduleNode"></div>
</div>

<div id="reporting_grid_CellReportTitle_11" class="rptCellReportTitle" widgetid="reporting_grid_CellReportTitle_11">
<div dojoattachpoint="divReportTitle" class="rptCellReportTitleSpanNode"><span class="dijit dijitInline dijitReset revitButton revitButtonHideBackground" data-dojo-attach-point="focusNode,titleNode,stateNode" role="button" aria-labelledby="revit_form_Button_31_label" data-dojo-attach-event="ondijitclick:_onClick" tabindex="0" id="revit_form_Button_31" widgetid="revit_form_Button_31" style="position: relative; user-select: none;">
<span class="dijitReset revitIconNode dijitNoIcon" data-dojo-attach-point="iconNode" style="display: none;"></span>
<span class="dijitReset dijitButtonText" id="revit_form_Button_31_label" data-dojo-attach-point="containerNode" style="padding-left: 0px; text-transform: none;"><b>Daily Tech Totals / Daily Tech Totals / Employee Daily Totals Report</b></span>
<span class="dijitReset revitIconNode revitIconRightNode dijitNoIcon" data-dojo-attach-point="iconRightNode"></span>
<input type="button" value="" class="dijitOffScreen" tabindex="-1" role="presentation" data-dojo-attach-point="valueNode">
</span></div>
<div dojoattachpoint="divNotes" class="rptCellReportTitleNotesNode"></div>
<div dojoattachpoint="divSchedule" class="rptCellReportTitleScheduleNode"></div>
</div>

最佳答案

没有ends-withXPath 1.0 ,但你可以使用

"//*[starts-with(@id,'revit_form_Button_' ) and substring(@id,string-length(@id)) = '0']"

满足附加条件

and also has the title "Daily Tech Totals / Daily Tech Totals / Employee Daily Totals Report"

添加一个子句,例如

child::*[text() = 'full content of the child element here']

child::*[contains(text(),'text to match here')]

到您的 XPath。在您的示例中,子元素是 <b> 。所以,你也可以写child::b而不是child::* .

把它们放在一起:

"//*[starts-with(@id,'revit_form_Button_')
and substring(@id,string-length(@id)) = '0'
and child::*[text() = 'Daily Tech Totals / Daily Tech Totals / Employee Daily Totals Report']
]"

这是一个单一的 XPath 表达式。为了便于阅读,分成几行,但也可以是一行。

关于以 X 开头并以零或最小数字结尾的 Python XPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52765861/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com