xPathをSeleniumで使用する場合、条件付きの親ノードに続く要素を探したいと思います。しかし、私は複数のノードの可能性があるを探すことを望みます。xPath:複数の次の要素が存在する場合はそれを選択します(OR)
span
またはp
いずれかとして、条件付きノード以下の要素を選択する方法はあり、それらの 1の場合は、存在していますか?
try:
elmnt = driver.find_element_by_xpath(
("//*[text()[contains(., 'myConditionString')]]" +
"/following::span or following::p") #← Find this
).text
except:
pass
else:
print elmnt
XPathは、両方を探している必要があります。
<root>
<b>myConditionString</b>
<span>Find me!</span>
</root>
この同時に:
<root>
<b>myConditionString</b>
<p>Find me!</p>
</root>
「HTML」サンプルコードを開き、 'find 'するターゲット要素を指定しますか? – Andersson