Python Forum
python selenium - get info from nested divs
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python selenium - get info from nested divs
#2
Hi,
You can try to identify the elements with their index, then illiterate on the index to the last one. Use this to identify by index
name=driver.find_element_by_xpath("(//*[contains(@class, 'student-name')])[1]")
print(name.text)
note the index [1]? you can replace it with a variable and illiterate with a For loop,else use a while loop(not soo elegant but can solve your problem)
x=1

while 1:
    try:
        name=driver.find_element_by_xpath("(//*[contains(@class, 'student-name')])[x]")
        print(name.text)
        #increment x by 1
        x+=1
    except Exception as e:
        break
damian0612 likes this post
Reply


Messages In This Thread
RE: python selenium - get info from nested divs - by law - Feb-25-2021, 09:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to iterate through a divs tag yokaso 3 3,246 Nov-01-2019, 07:48 AM
Last Post: buran
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,699 Nov-03-2017, 08:41 PM
Last Post: metulburr
  Web Crawler: How to find all divs that starts with... amandacstr 3 6,660 Oct-01-2016, 02:15 PM
Last Post: amandacstr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020