0

Here how can i get the total numbers of divs of class = "row ehi-pd", under each divs of class = "panel-content"? As shown in the picture.

it should give the output for each class = "panel-content" section separately, not combining all of them.

for example:

for 1st "panel-content" : 6

for 2nd "panel-content" : 5

for 3rd "panel-content" : 3

picture

Jaydeep
  • 775
  • 2
  • 8
  • 14
  • 1
    please include html using the snippet tool via [edit] and also your attempt at coding and where stuck. Guidance on posting is given in [ask] and [mcve]. – QHarr Mar 18 '19 at 07:29

3 Answers3

0

use find_elements_by_xpath and take the length count.

totalcount= len(driver.find_elements_by_xpath("//div[@class='panel-content']/div[@class='row ehi-pd']"))
print(totalcount)
KunduK
  • 32,888
  • 5
  • 17
  • 41
  • sir, actually i want the output for each class = "panel-content" section not combining all of them. for example: for 1st "panel-content" : 6, for 2nd "panel-content" : 5, for 3rd "panel-content" : 3 – Jaydeep Mar 18 '19 at 05:50
0

Good with @kajal solution but just want to add other option using css.

Using CSS:

panels = driver.find_elements_by_css_selector('.panel-content')
for panelNum in range(len(panels)):
    #get the divs count
    panelDivs = len(panels[panelNum].find_elements_by_css_selector("div.row.ehi-pd"))
    print str(panelNum+1) + " panel-content:" + str(panelDivs)
supputuri
  • 13,644
  • 2
  • 21
  • 39
  • sir, actually i want the output for each class = "panel-content" section not combining all of them. for example: for 1st "panel-content" : 6, for 2nd "panel-content" : 5, for 3rd "panel-content" : 3 – Jaydeep Mar 18 '19 at 05:52
0

To print the total numbers of nested <div> tags with class attribute as row ehi-pd within the ancestor <div> tag with class attribute as panel-content you can use either of the following Locator Strategies:

  • css_selector:

    print(len(driver.find_elements_by_css_selector("div.panel-content div.row.ehi-pd")))
    
  • xpath:

    print(len(driver.find_elements_by_xpath("//div[@class='panel-content']//div[@class='row ehi-pd']")))
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • sir, actually i want the output for each class = "panel-content" section not combining all of them. for example: for 1st "panel-content" : 6, for 2nd "panel-content" : 5, for 3rd "panel-content" : 3 – Jaydeep Mar 18 '19 at 05:50
  • In that case you have to update the question with text based HTML including a bit more of the outer HTML. – undetected Selenium Mar 18 '19 at 06:11