How to simulate onclick (JavaScript) using SeleniumPython - Stack Overflow

I am using PythonSelenium to click on an icon on a web site which downloads a file. I know how to clic

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".

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745462031a4628750.html

相关推荐

  • How to simulate onclick (JavaScript) using SeleniumPython - Stack Overflow

    I am using PythonSelenium to click on an icon on a web site which downloads a file. I know how to clic

    9小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信