1

I'm trying to get all the links and background images of the links inside a specific div But i can't seem to get them.

I'm trying to get the links and the background images inside paint_wrap div not paint_color.

HTML:

<div id="timer" style="display:inline-block">
  <div class="paint_wrap">
    <div class="paint_color">
      <img src="http://link.com/img/6EAwxqqt6J7aKcn6B6pO.gif" class="pick" width="30" height="30" border="0" alt="">
      <img src="http://link.com/img/arrow.gif" class="arrow" width="27" height="15" border="0" alt="">
    </div>

    <a href="tx.php?id=91760&amp;a=f899139df5e105939643&amp;s=dba9df3b0d18635362fd70d1ec51f201" target="_top" class="evJ3Ic2F5rYtXH4sPFKN" alt=""></a>
    <a href="tx.php?id=91760&amp;a=3644a684f98ea8fe223c&amp;s=dba9df3b0d18635362fd70d1ec51f201" target="_top" class="Rrp84pHupovp4G9R8DfJ" alt=""></a>
    <a href="tx.php?id=91760&amp;a=94f6d7e04a4d45203530&amp;s=dba9df3b0d18635362fd70d1ec51f201" target="_top" class="z071fnIXwHK7MDd7M58t" alt=""></a>
    <a href="tx.php?id=91760&amp;a=18d8042386b79e2c279f&amp;s=dba9df3b0d18635362fd70d1ec51f201" target="_top" class="UT94OVZ614YGvkFIuh4P" alt=""></a>
    <a href="tx.php?id=91760&amp;a=cee631121c2ec9232f3a&amp;s=dba9df3b0d18635362fd70d1ec51f201" target="_top" class="ZC7TO9wC576wN0Q9017j" alt=""></a>
    <a href="tx.php?id=91760&amp;a=d490d7b4576290fa60eb&amp;s=dba9df3b0d18635362fd70d1ec51f201" target="_top" class="G2e7xW9ii7Lp40kH140X" alt=""></a>
    <a href="http://www.other-link.com/?5974792" target="_blank" class="open"><img src="http://link.com/tx/o.gif" width="15" height="15" border="0" alt=""></a>
  </div>
</div>

WHAT I HAVE TRIED:

WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//*[@id='timer']/div/a"))) # Wait is fine
elements = self.driver.find_element(By.XPATH, "//*[@id='timer']/div/a")
for element in elements:
   print(element.get_attribute("href"))
   print(element.value_of_css_property("background-image"))  

I have also tried it with using css selector.

THE ERROR I GET: 'WebElement' object is not iterable

I'm hoping maybe someone could point me in the right direction.

1 Answer 1

3

You have to use 'find_elements' in the below line instead of 'find_element':

elements = self.driver.find_elements(By.XPATH, "//*[@id='timer']/div/a")
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I really can't believe i missed that mistake.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.