英文:
Xpath preceding
问题
DOM树
<span lightning-radiogroup_radiogroup="" class="slds-radio_faux"></span>
<span lightning-radiogroup_radiogroup="" class="slds-form-element__label">Yes</span></label>
我的XPath
//Label[text()='External']//following::fieldset//span[text()='Yes']
UI设计
我想要点击上述UI中的单选按钮,我的XPath已经准确定位到了'Yes'或'No',但遗憾的是无法点击单选按钮。
从我的XPath如何根据标签值(Yes、no)选择单选按钮。
英文:
DOM tree
<span lightning-radiogroup_radiogroup="" class="slds-radio_faux"></span>
<span lightning-radiogroup_radiogroup="" class="slds-form-element__label">Yes</span></label>
My XPath
//Label[text()='External']//following::fieldset//span[text()='Yes']
UI design
I want to click the radio button from the above UI, my XPath perfectly located the 'Yes' or 'No'
but unfortunately unable to click the radio button.
From my XPath how can I select the radio button based on the label value (Yes, no)
答案1
得分: 3
问题在于您正在选择单选按钮内部的跨度(span)。
您需要选择单选按钮节点。节点类似于这样:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<input type="radio" name="name" value="NO">
<label>
<span lightning-radiogroup_radiogroup="" class="slds-radio_faux">NO</span>
</label>
<input type="radio" name="name2" value="Yes">
<label>
<span lightning-radiogroup_radiogroup="" class="slds-form-element__label">Yes</span>
</label>
<!-- end snippet -->
因此,您需要类似于以下的 XPath:
//input[@type="radio"]/span[text()="YES"]/preceding::input
英文:
The problem is that you are selecting the span inside a radio button.
You need to select the radio-button node.
It would be a node similar to this:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<input type="radio" name="name" value="NO" >
<label>
<span lightning-radiogroup_radiogroup="" class="slds-radio_faux">NO</span>
</label>
<input type="radio" name="name2" value="Yes">
<label>
<span lightning-radiogroup_radiogroup="" class="slds-form-element__label">Yes</span>
</label>
<!-- end snippet -->
So you need an XPath like this:
//input[@type="radio"]/span[text()="YES"]/preceding::input
答案2
得分: 1
找到包含文本“Yes”的span
元素,然后找到其祖先元素,即label
,然后通过路径/ancestor::label/input
访问其内部的input
元素。
"//span[contains(text(), 'Yes')]/ancestor::label/input"
这是示例HTML:
英文:
Find the Yes
text span and then find it's ancestor element here it is label
then go to its input
element by /ancestor::label/input
"//span[contains(text(), 'Yes')]/ancestor::label/input"
答案3
得分: -1
尝试
//span[.='是']/preceding-sibling::span[@class='slds-radio_faux']
或者(最有可能的)
//span[.='是']/preceding::input[@type='radio']
英文:
Try
//span[.='Yes']/preceding-sibling::span[@class='slds-radio_faux']
or (most likely)
//span[.='Yes']/preceding::input[@type='radio']
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论