简体   繁体   中英

Find sibling node by xpath with Python selenium

Here is a fragment of xml. I need to use selenium to find the quote id value 1616968600 , but I'm new to xpath and I could use some help.

<div class="row">
    .....
</div>
<div class="row">
    <div class="col-md-2 ng-scope" style="font-weight: bold" translate="Business_Partner_Id">Business partner name: </div>
    <div class="col-md-2 ng-binding">Avnet Hall-Mark</div>
    <div class="col-md-2 ng-scope" style="font-weight: bold" translate="Quote_Id">Quote ID: </div>
    <div class="col-md-3 ng-binding">1616968600</div>               
</div>

Locate the div having Quote ID text and get the next sibling :

//div[contains(., "Quote ID")]/following-sibling::div

Usage:

quote_id_elm = driver.find_element_by_xpath('//div[contains(., "Quote ID")]/following-sibling::div')
print(quote_id_elm.text)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM