xPath last select element
Can someone help me to bring this code working? I have several select fields and I only want the last one in my v开发者_C百科ariable.
variable = browser.elements_by_xpath('//div[@class="nested-field"]//select[last()]
Thanks!
This is a FAQ: The []
operator in XPath has higher precedence (priority) than the //
pseudo-operator. This is why brackets must be used to change the default operator priorities. There are at least several similar questions with good explanations -- search for them and read and understand.
Instead of:
//div[@class="nested-field"]//select[last()]
Use:
(//div[@class="nested-field"]//select)[last()]
is the class attribute an exact match? if the mark up is like this
<div class="nested-field other">
...
then you'll have to either match by the exact class or use xpath contains.
精彩评论