79074674

Date: 2024-10-10 13:42:46
Score: 0.5
Natty:
Report link

When you use //div/a, it searches for the first <a> element in the entire document, not relative to the current column element. You should use a dot . at the beginning of the XPath to make it relative to the current element.

columns = driver.find_elements(By.XPATH, "//div[@class='table-columns']")
print(len(columns))

for column in columns:
    cell1 = column.find_element(By.XPATH, ".//div/a")
    cell2 = column.find_element(By.XPATH, ".//div")
    cell3 = column.find_element(By.XPATH, ".//div")
    cell4 = column.find_element(By.XPATH, ".//div")
    print(cell1.get_attribute('href'), cell2.text, cell3.text, cell4.text)
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): When you use
  • Low reputation (1):
Posted by: Alex Tbg