Issue
”’
<li class="rtLI">
<div class="rtMid">
<span class="rtSp"></span><span class="rtMinus"></span><img
src="certify.gif"
alt="#" class="rtImg"><span title="Test"
class="rtIn">dummy</span>
</div>
<ul class="rtUL">
<li class="rtLI">
<div class="rtTop">
<span class="rtSp"></span><img
src="certify.gif"
alt="#" class="rtImg"><span title="1"
class="rtIn">1</span>
</div>
</li>
<li class="rtLI">
<div class="rtMid">
<span class="rtSp"></span><img
src="certify.gif"
alt="#" class="rtImg"><span title="two"
class="rtIn">2</span>
</div>
</li>
<li class="rtLI">
<div class="rtMid">
<span class="rtSp"></span><img
src="certify.gif"
alt="#" class="rtImg"><span title="three"
class="rtIn">3</span>
</div>
</li>
</ul>
</li>
<li class="rtLI">
<li class="rtLI">
<li class="rtLI">
”’
I want to take count of li inside second ul class = rtUl and take the text inside each of them. how to do that using selenium.the problem is there are more ul and li are there with the same class name.i try to take the xpath of that ul and find the li inside that ul but it doesn’t comes well
Solution
lis=driver.find_elements_by_xpath("//li[@class='rtLI']/ul[@class='rtUL']/li[@class='rtLI']")
print(len(lis))
for li in list:
print(li.find_element_by_xpath(".//span[@class='rtIn']").text)
Get ul then li inside li class rtLI and print it’s len and then it’s text. So outputs 1,2,3?
Answered By – Arundeep Chohan
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0