Use watir web driver to click download icon

162 views Asked by At

I am trying to use watir to download files from a web page. Trying to figure out how to click the 'download icon' and then save the file.

The files are in a table, and I want to download each file with the word 'done' in the column and then same it as the report name.

The HTML is below:

<div class="portlet" id="homeStatus">
    <div class="portletHeader statusHeader">
        Reports and Request Status 
    </div>
    <div class="portletContent" id="statusContent">
        <div class="status">

            <div class="row-fluid boldText statusHeaderRow">
                <div class="span3">Name</div>
                <div class="span2">ID</div>
                <div class="span3">Date</div>
                <div class="span1">Status</div>
                <div class="span3">Actions</div>
            </div>

            <div class="row-fluid statusResultsText">

                <div class="span3 bold">

                        <span class="reportName">report2</span>

                </div>
                <div class="span2">429696109</div>
                <div class="span3">2015-06-14 20:06:55</div>
                <div class="span1">Done</div>
                <div class="span3 statusResultsActions iconSize16 statusActionPad" id="374189255">

                        <a href="#"><i class="icon-download-alt mediumBlueIcon downloadIcon" id = "/decision_support/Status_retrieve_request.aspx?questionid=Q10201&applicationid=300&JobId=429696109&status=D&Extension=xls&filename=/Outbound06/q3bk06m_429696109_A14A90C6XB906X4F05X8539XDE448240CE97&reqname=report2,429696109" title="Download"></i></a>
                        <a href="#" ><i class="icon-remove-sign redIcon removedrequestIcon" id = "d_429696109" title="Remove"></i></a>
                        <a href="#"><i class="icon-cog mediumBlueIcon modifydrequestIcon" id = "d_/decision_support/Report_Builder.aspx?country_cd=CA&qid=Q10201&exe_id=291&AppId=300&divid=1&JobId=429696109&reopen=true" title="Modify"></i></a>

                </div>
            </div>

            <div class="row-fluid statusResultsText alternateBackground">

                <div class="span3 bold">

                        <span class="reportName">Report Sun Jun 14 20:56:46 2015</span>

                </div>
                <div class="span2">429695641</div>
                <div class="span3">2015-06-14 20:01:34</div>
                <div class="span1">User Error</div>
                <div class="span3 statusResultsActions iconSize16 statusActionPad" id="374188794">

                </div>
            </div>              
        </div>
    </div>
</div>
1

There are 1 answers

0
sbs On
# iterate through rows
Browser.divs.each do |row|
  if row.div(:class => "span1").text == "Done"
    report_name = row.span(:class => "reportName").text
    row.divs.last.is.each do |i|
      # move the mouse to <i> tag and click the <a> link, if <i> is an icon and <a> link is not present
      Browser.driver.action.move_to(i.wd).click.perform
    end
  end
end