我得到以下 HTML 代碼:
<div><h6>abc/h6><p>date</p></div>
我可以根據文本使用硒成功找到此元素。現在的問題是<h6>可以包含不同的詞,如“def”或“ghi”。如何在以下 XPATH 中添加 OR?只有AND這是有效的:
"//div/p[contains(text(),'date') and preceding-sibling::h6[contains(text(),'abc')]]"
現在用 AND & OR 試過沒有成功
"//div/p[contains(text(),'date') and preceding-sibling::h6[contains(text(),'abc') or preceding-sibling::h6[contains(text(),'def')]]"
這也沒有成功
"//div/p[contains(text(),'date') and preceding-sibling::h6[contains(text(),'abc' or 'def')]]"
uj5u.com熱心網友回復:
在 for 的謂詞內部h6,測驗它是否包含 'abc'or包含 'def':
//div/p[contains(text(),'date')
and preceding-sibling::h6[contains(text(),'abc') or contains(text(),'def')]]
uj5u.com熱心網友回復:
使<p>謂語and與<h3>任何文本ABC或DEF如下:
//div//p[contains(.,'date')] [//preceding-sibling::h6[contains(.,'abc')] or //preceding-sibling::h6[contains(.,'def')]]
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/376134.html
上一篇:PythonSelenium:將結果列印為[<selenium.webdriver.remote.webelement.WebElement(session="9dc768d9ede7
