简体   繁体   English

使用Python Selenium通过xpath查找同级节点

[英]Find sibling node by xpath with Python selenium

Here is a fragment of xml. 这是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. 我需要使用selenium来找到报价ID值1616968600 ,但是我对xpath 并不陌生 ,可以使用一些帮助。

<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 : 找到具有Quote ID文本的div并获取下一个兄弟

//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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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