1

I have a website where i want to download an excel file. https://www.rivm.nl/media/smap/eenzaamheid.html

I want to be able to click the download button and then click download xls. To click the first button i tried the following:

WebDriverWait(driver, 10).until(EC.visibility_by_element_located(By.XPATH('//path[@d="M 11.6 5 L 11.6 17 M 7.4 12.6 L 11.6 17 L 15.799999999999999 12.6 M 3 19 L 3 21 L 21 21 L 21 19"]'))).click()

and

WebDriverWait(driver, 10).until(EC.visibility_by_element_located(By.XPATH('//path[@stroke-width="1.8"]'))).click()

WebDriverWait(driver, 10).until(EC.visibility_of_element_located(By.XPATH('//g[@aria-label="View export menu"]'))).click()

WebDriverWait(driver, 10).until(EC.visibility_of_element_located(By.XPATH('//g[@aria-label="Chart export menu"]'))).click()

For the last two i get the " 'str' object is not callable" error, the first two options just don't work at all.

I can't seem to be able to click the button. I can't really find an 'id' or an unique class/name (the print button has the same class value) for the button, which would make this a lot easier.

I think i would also not be able to then click the "XLS downloaden" as I can't find an ID here either.

So, how would i go about clicking the first button, and then clicking the "XLS downloaden" ?

2
  • Which is that download button? Commented Jul 15, 2020 at 15:54
  • the small down arrow next to the print icon Commented Jul 15, 2020 at 15:55

1 Answer 1

1

The desired element is a element so to click on the element instead of visibility_of_element_located() you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get("https://www.rivm.nl/media/smap/eenzaamheid.html")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.highcharts-container svg g[aria-label='View export menu'] rect"))).click()
    
  • Using XPATH:

    driver.get("https://www.rivm.nl/media/smap/eenzaamheid.html")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='highcharts-container ']//*[name()='svg']//*[name()='g' and @aria-label='View export menu']//*[name()='rect']"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

svg_css_click


References

You can find a couple of relevant discussions on interacting with SVG element in:

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

6 Comments

I already have all imports. I tried element to be clickable with By.XPATH('//g[@aria-label="Chart export menu"]'))).click(). But i still get the "not clickable" error. Are the name or id you provided the exact names and id's i could use?
@Raymondvanzonneveld Checkout the updated answer and let me know the status.
That totally works! thanks! And how would i then go about then clicking "XLS Downloaden" ? In the same fashion?
@Raymondvanzonneveld Glad to be able to help you. Can you raise a new question with your new requirement please? SO contributors will be happy to help you out.
Will do! Just have to wait a bit since i can only post once every 90 minutes. and thanks again!
|

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.