简体   繁体   English

Xpath:获取按钮包含特定文本的前一个 span 元素

[英]Xpath: Getting preceding span element where a button contains specific text

Trying to get the Button with span and text equals "Delete" as per below xpath selector for a later click尝试根据下面的 xpath 选择器获取具有跨度和文本等于“删除”的按钮,以便稍后单击

//text()='Delete'//preceding::span

But it does not work.但它不起作用。 Html is below. Html 如下。 How do i get the preceding element for click?如何获取点击的前面元素?

<oj-button :class="[['button-' + actionButton.data.style]]" chroming="full" on-oj-action="[[(event) => { handleActionButtonItem(
                  properties.actionButtons.menuItemAction,
                  actionButton.data.action,
                  properties.details
                )}]]" class="button-warn oj-button oj-button-full-chrome oj-button-text-only oj-enabled oj-complete oj-default">

                <!--oj-bind-text value='[[actionButton.data.name]]'--><!--ko text:actionButton.data.name--><!--/ko--><!--/oj-bind-text-->
              <div style="display: none;"></div><button class="oj-button-button" aria-labelledby="_ojcustomelem2902|text"><div class="oj-button-label"><span><span class="oj-button-text" id="_ojcustomelem2902|text">Delete</span></span></div></button></oj-button>

If I understand you correctly, you are looking for something like如果我理解正确,您正在寻找类似的东西

//button[.//span['Delete']]

Try it on your actual html and see if it works.在您的实际 html 上试一试,看看它是否有效。

Something like this像这样的东西

//button[.//span[.='Delete']]

Or if that span always has class="oj-button-text"或者,如果该跨度始终具有 class="oj-button-text"

//button[.//span[@class='oj-button-text' and .='Delete']]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM