我要做的是从下面的代码中获取子元素的数据:
<div class="ListContainer">
<ul class="uiList">
...
</ul>
<div class="expandedList">
<ul>
<div id="1012450"><a href="#"><img /></a></div>
<div id="1012451"><a href="#"><img /></a></div>
<div id="1012452"><a href="#"><img /></a></div>
<div id="1012453"><a href="#"><img /></a></div>
</ul>
</div>
<div class="expandedList">
<ul>
<div id="1012454"><a href="#"><img /></a></div>
<div id="1012455"><a href="#"><img /></a></div>
<div id="1012456"><a href="#"><img /></a></div>
<div id="1012457"><a href="#"><img /></a></div>
</ul>
</div>
....
....
</div>
我想获取expandedList类中每个div的id。我尝试使用xpath,但没有捕获所有的expandedList。
答案 0 :(得分:1)
div_ids = []
for div_element in driver.find_elements_by_css_selector('div.expandedList div[id]'):
div_ids.append(div_element.get_attribute('id'))