我正在尝试自动下载报告,但是我的脚本拒绝找到要单击的元素…
def wait_click(browser, by_what, where):
wait = WebDriverWait(browser, 20)
wait.until(EC.element_to_be_clickable((by_what, where))).click()
tillf_export = '//*[@id="panel__6940363340341543984_linkb_6940363340341543984"]'
# inside class
def download_tillf(self):
self.browser.get(system_export)
wait_click(self.browser, By.XPATH, tillf_export)
我已经尝试了所有可能的方法,从XPATH切换到使用父元素,甚至使用execute_script与js.
这是div:
<table class="dxrpControl" cellspacing="0" cellpadding="0" id="panel__6940363340341543984" border="0" style="border-collapse:collapse;border-collapse:separate;">
<tbody><tr>
<td id="panel__6940363340341543984_HC" class="dxrpHeader dxrp-headerClickable dx-borderBox" style="text-align: center; border-bottom: 1.33333px solid rgb(198, 198, 198); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px;"><div id="panel__6940363340341543984_CB" class="dxrpCollapseButton" style="margin-top: 1px;">
<img id="panel__6940363340341543984_CBImg" class="dxWeb_rpCollapseButton" src="/test/jlltp02/sjalvservicerdr/DXR.axd?r=1_89-UNelo" alt="Collapse/Expand">
</div><div class="dxrpHCW" style="padding-right: 19px;">
** <span id="panel__6940363340341543984_RPHT" class="dxrpHT dx-vam">Tillfällig export</span>
</div></td>
</tr><tr class="dxrpCR">
<td id="panel__6940363340341543984_RPC" class="dxrp dxrpcontent dx-borderBox"><div class="dxrpAW" style="">
<div id="panel__6940363340341543984_CRC" class="dx-borderBox dxrpCW">
<table border="0">
<tbody><tr>
<td><span class="UTDATANODTITLEDESC">Tillfällig export kan användas för att snabbt ta ned svaret på en fråga genom att bara ändra den i "Automatiska frågor". Detta för att slippa gå in i Citrix och spara ned filen på M:.</span></td>
</tr><tr>
<td valign="top"><a id="panel__6940363340341543984_linkb_6940363340341543984" class="UTDATANODLINK" href="javascript:outputClick('6940363340341543984');">>> Tillfällig export</a></td>
</tr>
</tbody></table>
</div>
</div></td>
</tr>
</tbody></table>
有人能看出我做错了什么吗?将永远感激!
所需元素的id
属性看起来是动态的,元素本身可能是一个动态元素,所以点击可点击元素,你需要为element_to_be_clickable()诱导WebDriverWait,你可以使用以下定位策略:
PARTIAL_LINK_TEXT:
Tillfällig export
使用<<li>em> CSS_SELECTOR :
a.UTDATANODLINK[id*='linkb']
使用<<li>em> XPATH :
//a[@class='UTDATANODLINK' and contains(., 'Tillfällig export')]