Need a help with some ideas how to click on a generic element from a generic list.
For example, I need to select last list element, that is <div class="venue-item">
, from the following list: <div id="list">
. And click on the following tag <a href="#" class="venue-actions dropdown-toggle" data-toggle="dropdown"></a>
May be to create a Python library?
<div id="list" class="row" style="opacity: 1;">
<div class="venue-item">
<a class="venue-actions dropdown-toggle" data toggle="dropdown" href="#"></a>
<ul class="dropdown-menu">
<h3>test_by_alex_lggge</h3>
<a class="show-details-btn" href="#">
<div class="venue-item">
<a class="venue-actions dropdown-toggle" data toggle="dropdown" href="#"></a>
<ul class="dropdown-menu">
<h3>test_by_alex_lggge</h3>
<a class="show-details-btn" href="#">
<div class="venue-item">
<a class="venue-actions dropdown-toggle" data toggle="dropdown" href="#"></a>
<ul class="dropdown-menu">
<h3>test_by_alex_lggge</h3>
<a class="show-details-btn" href="#">
<div class="venue-item">
<a class="venue-actions dropdown-toggle" data toggle="dropdown" href="#"></a>
<ul class="dropdown-menu">
<h3>test_by_alex_lggge</h3>
<a class="show-details-btn" href="#">
<div class="venue-item">
<a class="venue-actions dropdown-toggle" data toggle="dropdown" href="#"></a>
<ul class="dropdown-menu">
<h3>test_by_alex_lggge</h3>
<a class="show-details-btn" href="#">
<div class="venue-item">
<a class="venue-actions dropdown-toggle" data toggle="dropdown" href="#"></a>
<ul class="dropdown-menu">
<h3>test_by_alex_lggge</h3>
<a class="show-details-btn" href="#">
<div class="venue-item">
<a class="venue-actions dropdown-toggle" data toggle="dropdown" href="#"></a>
<ul class="dropdown-menu">
<h3>test_by_alex_lggge</h3>
<a class="show-details-btn" href="#">
<div class="item-detail">
<a class="venue-actions dropdown-toggle" data toggle="dropdown" href="#"></a>
<ul class="dropdown-menu">
<h3>test_by_alex_lggge</h3>
<a class="show-details-btn" href="#">
</div>
<div class="organisation-details">
<div id="delete-schedule-26681" class="modal fade" role="dialog">
</div>
</div>
To get the last <div>
with class="venue-item"
, use this xpath:
(//div[@id="list"]/div[@class="venue-item"])[last()]
Some explanations - the first part ( //div[@id="list"]
) gets all elements with such id value (in your sample - 1). The second ( div[@class="venue-item"]
) selects all of its direct descendants - this will get us a list of all the div
with such class. The last part - [last()]
will return the last element of the returned list.
The brackets around part 1 & 2 are here, because of xpath precedence and scope of axes and operators . In this particular set it is not needed, but if the connector b/n the 1st part and the 2nd was //
, it would made a big difference.
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.