3

I am using Python/Selenium to click on an icon on a web site which downloads a file. I know how to click on regular buttons using Selenium but this one is a bit tricky as it's not a regular button and it's making a Javascript call. I've tried several find_element_by calls but was unable to access this element. Can anyone think of a way to click on this using a selenium call?

When I do inspect element for the download icon in my web browser this is what I get:

<a href="javascript: void(0)" class="pull-right margin-r" onclick="
                        document.theForm.action='/p1234/DownloadData';
                        $('#theForm').append($('<input>', {type:'hidden', name:'Download', value:'Download'})).submit();
                    "><img src="/images/download.png" title="Download" alt="Download" style="" border="0"></a>

thanks in advance

1 Answer 1

2

How about locating the element by the part of the onclick attribute:

driver.find_element_by_css_selector("a[onclick*=DownloadData]").click();

where *= means "contains".

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

Comments

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.