一个元素可以有两个 XML 视图:
1.
<div class="GRUPP_FLG">
<div role="radiogroup">
<div class="radioButton">
<div role="radio" aria-label="Yes">
<input type="radio">
<span>Yes</span>
</div>
</div>
<div class="radioButton">
<div role="radio" aria-label="No">
<input type="radio">
<span>No</span>
</div>
</div>
</div>
</div>
2.
<div class="GRUPP_FLG">
<div>
<span title="No" class="readonlyField">
No
</span>
</div>
</div>
在第一种情况下,我需要单击单选按钮。
WebElement radioButton = elementWithRadiogroup.findElement(By.xpath(".//*[@aria-label='No']"));
radioButton.click();
在第二种情况下,我需要检查 span 是否有一个类readonlyField
if(!elementWithSpan.getAttribute("class").contains("readonlyField"))
throw new AutotestError("Error");
如果使用
//div[contains(@class, 'GRUPP_FLG')](//*[@role='radiogroup'] | //span[contains(@class, 'readonlyField')])
然后发生错误:
org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the XPath expression
because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document'
我怎么能得到 XPath?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句