0

Objective: To loop over Span items (inform of buttons) on a Web Page and get corresponding href values. This page can have multiple buttons kind of elements and its dynamic and will have value from 1 to n.

Input html code:

enter image description here

and this class='mb-text' values varies from 1 to n.

So Now I need to find if this span class exist and if exist, then loop through it and get all href related to those

The below statements were not able to locate intended elements returned empty list

elements1 = driver.find_elements_by_xpath("(//span[contains(@class,'mb-text')])")
elements1 = driver.find_elements_by_css_selector('maxbutton-1 maxbutton maxbutton-download-link')

Please suggest

1
  • 1
    can you share the url? Commented Sep 12, 2021 at 17:05

1 Answer 1

0

I guess you are missing a wait before accessing these elements.
Please try this:

wait = WebDriverWait(driver, 20)
wait.until(EC.visibility_of_element_located((By.XPATH, "//span[contains(@class,'mb-text')]")))
time.sleep(1)
elements1 = driver.find_elements_by_xpath("//span[contains(@class,'mb-text')]")

You will need these imports:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

Also possibly there is an iframe there.
If so you will have to switch into that iframe.

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

2 Comments

No luck buddy. I guess its not problem I see with time wait. But I am doing some mistake to select by xpath or css from input of html which I have given in original post. Not sure what I am missing, since its returning empty list. I need some suggestion how to correctly access those elements based on html given in original post
can you share a link to that page?

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.