Thank you for your response, Dorian.
I didn't express myself clearly, so let me explain it better below.
In the example code I provided, the ID and attribute of the DIVs are explicitly specified. It's what you locate using EdgeFindElements.
I'm dealing with a situation where the IDs of the child DIVs are randomly generated, and they vary based on the system's order number. Therefore, I don't have that information beforehand. That's why I need to traverse through the parent DIV (which remains constant) and extract the randomly generated ID from each child DIV. Once I have the ID, I can extract other related information that will be generated.
Did I explain myself better?
I apologize as I am a beginner, and I have already struggled with the codes you provided without finding a solution. That's why I'm reaching out to you for help.
In Python it would look something like this:
Code: Select all
from selenium import webdriver
# Initialize the Selenium driver
driver = webdriver.Chrome()
# Access the HTML document
driver.get("url_of_the_html_document")
# Locate the parent div using XPath
parent_div = driver.find_element_by_xpath('//*[@class="q"]')
# Locate all the child divs within the parent div
child_divs = parent_div.find_elements_by_tag_name('div')
# Iterate over the child divs and retrieve the ID and class of each
for child_div in child_divs:
div_id = child_div.get_attribute('id')
div_class = child_div.get_attribute('class')
print("ID:", div_id)
print("Class:", div_class)
# Close the Selenium driver
driver.quit()