Counting the list within HTML structure using Selenium Webdriver

0 votes

I have HTML with the following structure and wish to how the inner most li's:

<div id="topDiv" ..... >

    <div ...... >

        <ul class="lists" ...>

            <li .....>

                <ul ....>

                    <li id="importantlist1">

                    <li id="importantlist2">

                    ...

                    ...

                </ul>

           </li>

       </ul>

   </div>

</div>

 

I want to count the li's i.e. total number. The top div and first ul has id's as well as each important li. I tried using cssSelector, xpath but Its not working.

Jul 3, 2018 in Selenium by Martin
• 4,220 points
887 views

1 answer to this question.

0 votes
Try Below code:

This should work

driver.findElements(By.xpath("//li[contains(@id,importantlist')]")).size()
answered Jul 3, 2018 by Samarpit
• 5,130 points

Related Questions In Selenium

0 votes
1 answer

What is the command to press enter inside the HTML textarea using Selenium Webdriver?

Hey Akash, Selenium provides sendKeys() method to ...READ MORE

answered Jun 25 in Selenium by Anvi
• 12,840 points
34 views
0 votes
1 answer

How to scroll the Page up or down in Selenium WebDriver? (using java)

Its pretty simple. Check out the below ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,090 points
7,111 views
0 votes
1 answer

How can I download the *.jar file from http:// seleniumhq.org using selenium WebDriver?

For Selenium Standalone Server use this: profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/java-archive"); and ...READ MORE

answered Apr 9, 2018 in Selenium by Martin
• 4,220 points
459 views
0 votes
1 answer

Select an item from a dropdown list using Selenium WebDriver

Use this then it will work - new ...READ MORE

answered Apr 9, 2018 in Selenium by Vardy
• 2,250 points
2,014 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
548 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
882 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
546 views
0 votes
1 answer

Maximizing the browser window in Selenium WebDriver using C#

Check this first: http://code.google.com/p/selenium/issues/detail?id=174 You Can use the JavascriptExector as follows: public ...READ MORE

answered May 2, 2018 in Selenium by Samarpit
• 5,130 points
70 views
0 votes
2 answers

How to get HTML Source of WebElement in Selenium WebDriver using Python?

You can read innerHTML attribute to get source of ...READ MORE

answered Jun 13, 2018 in Selenium by Samarpit
• 5,130 points
13,717 views