admin管理员组

文章数量:1429833

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

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

Share Improve this question edited Apr 30, 2016 at 20:21 user3695968 asked Apr 30, 2016 at 20:11 user3695968user3695968 331 gold badge1 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 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".

本文标签: How to simulate onclick (JavaScript) using SeleniumPythonStack Overflow