嗨,我正在尝试使用带有python的Selenium Webdriver从网站下载文件。
我的index.html位于链接html code
中我能够从网页中识别下载路径,但无法在程序中使用它。
.grid1531406090815 .ui-grid-coluiGrid-0004 { min-width: 138px; max-width: 138px; } .grid1531406090815 .ui-grid-coluiGrid-000B { min-width: 90px; max-width: 90px; }</style><div class="ui-grid-contents-wrapper"><!----><!----><div role="grid" ui-grid-one-bind-id-grid="'grid-container'" class="ui-grid-render-container ui-grid-render-container-body" ng-style="{ 'margin-left': colContainer.getMargin('left') + 'px', 'margin-right': colContainer.getMargin('right') + 'px' }" ui-grid-render-container="" container-id="'body'" col-container-name="'body'" row-container-name="'body'" bind-scroll-horizontal="true" bind-scroll-vertical="true" enable-horizontal-scrollbar="grid.options.enableHorizontalScrollbar" enable-vertical-scrollbar="grid.options.enableVerticalScrollbar" id="1531406090815-grid-container" style="margin-left: 0px; margin-right: 0px;"><!-- All of these dom elements are replaced in place --><div role="rowgroup" class="ui-grid-header"><!-- theader --><div class="ui-grid-top-panel"><div class="ui-grid-header-viewport"><div class="ui-grid-header-canvas"><div class="ui-grid-header-cell-wrapper" ng-style="colContainer.headerCellWrapperStyle()"><div role="row" class="ui-grid-header-cell-row"><!----><div class="ui-grid-header-cell ui-grid-clearfix ui-grid-coluiGrid-0004" ng-repeat="col in colContainer.renderedColumns track by col.uid" ui-grid-header-cell="" col="col" render-index="$index" style=""><div role="columnheader" ng-class="{ 'sortable': sortable }" ui-grid-one-bind-aria-labelledby-grid="col.uid + '-header-text ' + col.uid + '-sortdir-text'" aria-sort="none" aria-labelledby="1531406090815-uiGrid-0004-header-text 1531406090815-uiGrid-0004-sortdir-text"><div role="button" tabindex="0" class="ui-grid-cell-contents ui-grid-header-cell-primary-focus" col-index="renderIndex"><span class="ui-grid-header-cell-label" ui-grid-one-bind-id-grid="col.uid + '-header-text'" id="1531406090815-uiGrid-0004-header-text">Name / ID</span> <span ui-grid-one-bind-id-grid="col.uid + '-sortdir-text'" ui-grid-visible="col.sort.direction" aria-label="Sort None" class="ui-grid-invisible" id="1531406090815-uiGrid-0004-sortdir-text"><i ng-class="{ 'ui-grid-icon-up-dir': col.sort.direction == asc, 'ui-grid-icon-down-dir': col.sort.direction == desc, 'ui-grid-icon-blank': !col.sort.direction }" title="" aria-hidden="true" class="ui-grid-icon-blank"></i> <sub ui-grid-visible="isSortPriorityVisible()" class="ui-grid-sort-priority-number ui-grid-invisible">1</sub></span></div><!----><div role="button" tabindex="0" ui-grid-one-bind-id-grid="col.uid + '-menu-button'" class="ui-grid-column-menu-button" ng-if="grid.options.enableColumnMenus && !col.isRowHeader && col.colDef.enableColumnMenu !== false" ng-click="toggleMenu($event)" ng-class="{'ui-grid-column-menu-button-last-col': isLastCol}" ui-grid-one-bind-aria-label="i18n.headerCell.aria.columnMenuButtonLabel" aria-haspopup="true" id="1531406090815-uiGrid-0004-menu-button" aria-label="Column Menu"><i class="ui-grid-icon-angle-down" aria-hidden="true"> </i></div><!----><div ui-grid-filter=""></div></div></div><!----><div class="ui-grid-header-cell ui-grid-clearfix ui-grid-coluiGrid-000B" ng-repeat="col in colContainer.renderedColumns track by col.uid" ui-grid-header-cell="" col="col" render-index="$index" style=""><div role="columnheader" ng-class="{ 'sortable': sortable }" ui-grid-one-bind-aria-labelledby-grid="col.uid + '-header-text ' + col.uid + '-sortdir-text'" aria-sort="none" aria-labelledby="1531406090815-uiGrid-000B-header-text 1531406090815-uiGrid-000B-sortdir-text"><div role="button" tabindex="0" class="ui-grid-cell-contents ui-grid-header-cell-primary-focus" col-index="renderIndex"><span class="ui-grid-header-cell-label" ui-grid-one-bind-id-grid="col.uid + '-header-text'" id="1531406090815-uiGrid-000B-header-text">Status</span> <span ui-grid-one-bind-id-grid="col.uid + '-sortdir-text'" ui-grid-visible="col.sort.direction" aria-label="Sort None" class="ui-grid-invisible" id="1531406090815-uiGrid-000B-sortdir-text"><i ng-class="{ 'ui-grid-icon-up-dir': col.sort.direction == asc, 'ui-grid-icon-down-dir': col.sort.direction == desc, 'ui-grid-icon-blank': !col.sort.direction }" title="" aria-hidden="true" class="ui-grid-icon-blank"></i> <sub ui-grid-visible="isSortPriorityVisible()" class="ui-grid-sort-priority-number ui-grid-invisible">1</sub></span></div><!----><div role="button" tabindex="0" ui-grid-one-bind-id-grid="col.uid + '-menu-button'" class="ui-grid-column-menu-button ui-grid-column-menu-button-last-col" ng-if="grid.options.enableColumnMenus && !col.isRowHeader && col.colDef.enableColumnMenu !== false" ng-click="toggleMenu($event)" ng-class="{'ui-grid-column-menu-button-last-col': isLastCol}" ui-grid-one-bind-aria-label="i18n.headerCell.aria.columnMenuButtonLabel" aria-haspopup="true" id="1531406090815-uiGrid-000B-menu-button" aria-label="Column Menu" style=""><i class="ui-grid-icon-angle-down" aria-hidden="true"> </i></div><!----><div ui-grid-filter=""></div></div></div><!----></div></div></div></div></div></div><div role="rowgroup" class="ui-grid-viewport" ng-style="colContainer.getViewportStyle()" ui-grid-viewport="" style="overflow: scroll;"><!-- tbody --><div class="ui-grid-canvas"><!----><div ng-repeat="(rowRenderIndex, row) in rowContainer.renderedRows track by $index" class="ui-grid-row" ng-style="Viewport.rowStyle(rowRenderIndex)" style=""><div role="row" ui-grid-row="row" row-render-index="rowRenderIndex"><!----><div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" ui-grid-one-bind-id-grid="rowRenderIndex + '-' + col.uid + '-cell'" class="ui-grid-cell ui-grid-coluiGrid-0004" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" role="gridcell" ui-grid-cell="" id="1531406090815-0-uiGrid-0004-cell"><div style="height: 80px; margin: 13px 0 0 5px; font-weight: 700; color: #585858; font-size: 12px;" class="ui-grid-col-2"><div class="ui-grid-col-2-name" style="font-size: 12px; text-align: left; margin: 0px">Report Thu Jul 12 09:30:36 2018</div><div class="ui-grid-col-2-id-date"><span class="ui-grid-col-2-id" style="margin: 0"><i>ID :</i> 506380430</span><br><span class="ui-grid-col-2-date" style="margin:0px;"><i>Date :</i> 2018-07-12 09:04:28</span></div></div></div><!----><div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" ui-grid-one-bind-id-grid="rowRenderIndex + '-' + col.uid + '-cell'" class="ui-grid-cell ui-grid-coluiGrid-000B" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" role="gridcell" ui-grid-cell="" id="1531406090815-0-uiGrid-000B-cell"><div style="height: 80px; margin: 13px 0 0 0;"><div style="height: 31px; text-align: left; font-weight: 700; color: #585858; font-size: 12px; margin-left: 0px">Retrieved</div><div style="height: 12px; text-align: left; font-size: 12px;" class="request-icons"><!----><span class="icon-download" style="color: green;margin: 0px 10px 0 0; font-size: 12px; cursor:pointer;" ng-if="row.entity.StatusCode === 'D' || row.entity.StatusCode === 'R' || row.entity.StatusCode === 'E' || row.entity.StatusCode === 'N' " title="Download" ng-click="grid.appScope.$ctrl.openPage(row.entity.url, 'window')" role="button" tabindex="0"></span><!----><!----><span title="Delete" ng-click="grid.appScope.$ctrl.deleteRequest(row.entity.jobId)" class="icon-trash" style="color: red; margin: 5px 5px 5px 0; font-size: 12px; cursor: pointer;" ng-if="row.entity.StatusCode === 'W' || row.entity.StatusCode === 'A' || row.entity.StatusCode === 'P' || row.entity.StatusCode === 'F' || row.entity.StatusCode === 'B' || row.entity.StatusCode === 'D' || row.entity.StatusCode === 'R' || row.entity.StatusCode === 'E' || row.entity.StatusCode === 'N'" role="button" tabindex="0"></span><!----><a ng-click="grid.appScope.$ctrl.openPage(row.entity.modifyUrl);grid.appScope.$ctrl.InsertPageCount(2,row.entity.id,row.entity.name)"><!----><span title="Settings" class="icon-settings" style="color: #000; cursor: pointer; margin: 5px; font-size: 12px;" ng-if="row.entity.StatusCode === 'W' || row.entity.StatusCode === 'A' || row.entity.StatusCode === 'P' || row.entity.StatusCode === 'F' || row.entity.StatusCode === 'B' || row.entity.StatusCode === 'D' || row.entity.StatusCode === 'R' || row.entity.StatusCode === 'E' || row.entity.StatusCode === 'N'"></span><!----></a></div></div></div><!----></div></div><!----><div ng-repeat="(rowRenderIndex, row) in rowContainer.renderedRows track by $index" class="ui-grid-row" ng-style="Viewport.rowStyle(rowRenderIndex)"><div role="row" ui-grid-row="row" row-render-index="rowRenderIndex"><!----><div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" ui-grid-one-bind-id-grid="rowRenderIndex + '-' + col.uid + '-cell'" class="ui-grid-cell ui-grid-coluiGrid-0004" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" role="gridcell" ui-grid-cell="" id="1531406090815-1-uiGrid-0004-cell"><div style="height: 80px; margin: 13px 0 0 5px; font-weight: 700; color: #585858; font-size: 12px;" class="ui-grid-col-2"><div class="ui-grid-col-2-name" style="font-size: 12px; text-align: left; margin: 0px">Report Thu Jul 12 09:30:36 2018</div><div class="ui-grid-col-2-id-date"><span class="ui-grid-col-2-id" style="margin: 0"><i>ID :</i> 506377486</span><br><span class="ui-grid-col-2-date" style="margin:0px;"><i>Date :</i> 2018-07-12 08:34:06</span></div></div></div><!----><div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" ui-grid-one-bind-id-grid="rowRenderIndex + '-' + col.uid + '-cell'" class="ui-grid-cell ui-grid-coluiGrid-000B" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" role="gridcell" ui-grid-cell="" id="1531406090815-1-uiGrid-000B-cell"><div style="height: 80px; margin: 13px 0 0 0;"><div style="height: 31px; text-align: left; font-weight: 700; color: #585858; font-size: 12px; margin-left: 0px">Retrieved</div><div style="height: 12px; text-align: left; font-size: 12px;" class="request-icons"><!----><span class="icon-download" style="color: green;margin: 0px 10px 0 0; font-size: 12px; cursor:pointer;" ng-if="row.entity.StatusCode === 'D' || row.entity.StatusCode === 'R' || row.entity.StatusCode === 'E' || row.entity.StatusCode === 'N' " title="Download" ng-click="grid.appScope.$ctrl.openPage(row.entity.url, 'window')" role="button" tabindex="0"></span><!----><!----><span title="Delete" ng-click="grid.appScope.$ctrl.deleteRequest(row.entity.jobId)" class="icon-trash" style="color: red; margin: 5px 5px 5px 0; font-size: 12px; cursor: pointer;" ng-if="row.entity.StatusCode === 'W' || row.entity.StatusCode === 'A' || row.entity.StatusCode === 'P' || row.entity.StatusCode === 'F' || row.entity.StatusCode === 'B' || row.entity.StatusCode === 'D' || row.entity.StatusCode === 'R' || row.entity.StatusCode === 'E' || row.entity.StatusCode === 'N'" role="button" tabindex="0"></span><!----><a ng-click="grid.appScope.$ctrl.openPage(row.entity.modifyUrl);grid.appScope.$ctrl.InsertPageCount(2,row.entity.id,row.entity.name)"><!----><span title="Settings" class="icon-settings" style="color: #000; cursor: pointer; margin: 5px; font-size: 12px;" ng-if="row.entity.StatusCode === 'W' || row.entity.StatusCode === 'A' || row.entity.StatusCode === 'P' || row.entity.StatusCode === 'F' || row.entity.StatusCode === 'B' || row.entity.StatusCode === 'D' || row.entity.StatusCode === 'R' || row.entity.StatusCode === 'E' || row.entity.StatusCode === 'N'"></span><!----></a></div></div></div><!----></div></div><!----><div ng-repeat="(rowRenderIndex, row) in rowContainer.renderedRows track by $index" class="ui-grid-row" ng-style="Viewport.rowStyle(rowRenderIndex)"><div role="row" ui-grid-row="row" row-render-index="rowRenderIndex"><!----><div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" ui-grid-one-bind-id-grid="rowRenderIndex + '-' + col.uid + '-cell'" class="ui-grid-cell ui-grid-coluiGrid-0004" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" role="gridcell" ui-grid-cell="" id="1531406090815-2-uiGrid-0004-cell"><div style="height: 80px; margin: 13px 0 0 5px; font-weight: 700; color: #585858; font-size: 12px;" class="ui-grid-col-2"><div class="ui-grid-col-2-name" style="font-size: 12px; text-align: left; margin: 0px">Report Thu Jul 12 09:30:36 2018</div><div class="ui-grid-col-2-id-date"><span class="ui-grid-col-2-id" style="margin: 0"><i>ID :</i> 506377300</span><br><span class="ui-grid-col-2-date" style="margin:0px;"><i>Date :</i> 2018-07-12 08:31:59</span></div></div></div><!----><div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" ui-grid-one-bind-id-grid="rowRenderIndex + '-' + col.uid + '-cell'" class="ui-grid-cell ui-grid-coluiGrid-000B" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" role="gridcell" ui-grid-cell="" id="1531406090815-2-uiGrid-000B-cell"><div style="height: 80px; margin: 13px 0 0 0;"><div style="height: 31px; text-align: left; font-weight: 700; color: #585858; font-size: 12px; margin-left: 0px">No Data Found</div><div style="height: 12px; text-align: left; font-size: 12px;" class="request-icons"><!----><span class="icon-download" style="color: green;margin: 0px 10px 0 0; font-size: 12px; cursor:pointer;" ng-if="row.entity.StatusCode === 'D' || row.entity.StatusCode === 'R' || row.entity.StatusCode === 'E' || row.entity.StatusCode === 'N' " title="Download" ng-click="grid.appScope.$ctrl.openPage(row.entity.url, 'window')" role="button" tabindex="0"></span><!----><!----><span title="Delete" ng-click="grid.appScope.$ctrl.deleteRequest(row.entity.jobId)" class="icon-trash" style="color: red; margin: 5px 5px 5px 0; font-size: 12px; cursor: pointer;" ng-if="row.entity.StatusCode === 'W' || row.entity.StatusCode === 'A' || row.entity.StatusCode === 'P' || row.entity.StatusCode === 'F' || row.entity.StatusCode === 'B' || row.entity.StatusCode === 'D' || row.entity.StatusCode === 'R' || row.entity.StatusCode === 'E' || row.entity.StatusCode === 'N'" role="button" tabindex="0"></span><!----><a ng-click="grid.appScope.$ctrl.openPage(row.entity.modifyUrl);grid.appScope.$ctrl.InsertPageCount(2,row.entity.id,row.entity.name)"><!----><span title="Settings" class="icon-settings" style="color: #000; cursor: pointer; margin: 5px; font-size: 12px;" ng-if="row.entity.StatusCode === 'W' || row.entity.StatusCode === 'A' || row.entity.StatusCode === 'P' || row.entity.StatusCode === 'F' || row.entity.StatusCode === 'B' || row.entity.StatusCode === 'D' || row.entity.StatusCode === 'R' || row.entity.StatusCode === 'E' || row.entity.StatusCode === 'N'"></span><!----></a></div></div></div><!----></div></div><!----></div></div><!----><!----></div><!----><!----><!----><div class="ui-grid-column-menu" ui-grid-column-menu="" ng-if="grid.options.enableColumnMenus"><!----></div><!----><div ng-transclude=""></div></div></div><!---->
我正在下载这种类型的span类。
<span class="icon-download" style="color: green;margin: 0px 10px 0 0; font-size: 12px; cursor:pointer;" ng-if="row.entity.StatusCode === 'D' || row.entity.StatusCode === 'R' || row.entity.StatusCode === 'E' || row.entity.StatusCode === 'N' " title="Download" ng-click="grid.appScope.$ctrl.openPage(row.entity.url, 'window')" role="button" tabindex="0"></span>
到目前为止,我已经能够登录并迁移到网站中的链接,但是在这一点上还是很震惊
browser = webdriver.Chrome('C:\Users\suguran\chromedriver_win32\chromedriver.exe')
browser.get('https://retaillink.wal-mart.com/rl_home/')
username = browser.find_element_by_id("txtUser")
password = browser.find_element_by_id("txtPass")
username.send_keys("username")
password.send_keys("Password")
browser.find_element_by_xpath("//button").click()
browser.get('https://retaillink.wal-mart.com/rl_home/#/request-list/requests')
我正在尝试点击图片中的特定下载图标。
谢谢。
答案 0 :(得分:1)
您可以尝试使用此xpath:
//span[@class='icon-download' and @title='Download' and contains(@ng-click,'grid.appScope.$ctrl.openPage(row.entity.url, ')]