0

I want a quick export of all events, with event type and event title from my local html file.

i=0
for elements in driver.find_elements_by_class_name('event'):
    entryType = driver.find_element_by_class_name('event-type')
    contentEntryType = entryType.get_attribute("innerHTML")
    print (contentEntryType)
    entryTitle = driver.find_element_by_class_name('event-title')
    contentEntryTitle = entryTitle.get_attribute("innerHTML")
    print (contentEntryTitle)
    i=i+1
    print (i)

The counter runs correctly up to the number of events. Event type and event title will be printed.

But event type and event title will stay identical for all events, where i runs up correctly to 251. Can anybody point me to what I have overseen?

1 Answer 1

3

The problem is that you are using driver to find event specific information, but should use the loop variable - elements in your case. I would also rename it to, say, event for readability:

for event in driver.find_elements_by_class_name('event'):
    entryType = event.find_element_by_class_name('event-type')
    entryTitle = event.find_element_by_class_name('event-title')

In other words, now the event type and title search would be context-specific, specific to every event found in the loop.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.