Python Selenium按钮不会单击 [英] Python Selenium Button Won't Click

查看:85
本文介绍了Python Selenium按钮不会单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试单击转到"按钮,但是它没有起作用.

I'm trying to click this Go button but it hasn't been working.

这是HTML:

<a name="DERIVED_SSS_SCL_SSS_GO_1" id="DERIVED_SSS_SCL_SSS_GO_1" role="button" onclick="javascript:cancelBubble(event);" href="javascript:submitAction_win1(document.win1,'DERIVED_SSS_SCL_SSS_GO_1');"><img src="https://sims-prd.sfu.ca/cs/csprd/cache/PT_NAV_GO_1.gif" name="DERIVED_SSS_SCL_SSS_GO_1$IMG" alt="Go" title="Go" border="0"></a>

我尝试了以下操作:

driver.find_element_by_xpath('//*[@id="DERIVED_SSS_SCL_SSS_GO_1"]').click()
driver.find_element_by_xpath("//a[contains(@href,'win1')]").click()
driver.find_element_by_id('DERIVED_SSS_SCL_SSS_GO_1').click()

感谢您的帮助.谢谢.

包括更多HTML,希望能够缩小我的问题范围.我一定想念这里的东西.

Included more HTML to hopefully be able to narrow down my issue. I must be missing something contained in here.

<td height="28"></td>
<td colspan="4" align="left" valign="top">
<div id="win1div$ICField281">
<table cols="1" class="PABACKGROUNDINVISIBLEWBO" cellspacing="0" cellpadding="2" width="163">
<tbody><tr>
<td class="PAGROUPBOXLABELINVISIBLE" align="left">Group Box</td>
</tr>

<tr>
<td width="161">
<table role="presentation" id="ACE_$ICField281" cols="3" class="PABACKGROUNDINVISIBLE" style="border-style:none" cellspacing="0" cellpadding="0" border="0" width="161">
<tbody><tr>
<td width="3" height="0"></td>
<td width="132"></td>
<td width="26"></td>
</tr>

<tr>
<td colspan="2" height="1"></td>
<td rowspan="2" align="left" valign="top" nowrap="nowrap">
<div id="win1divDERIVED_SSS_SCL_SSS_GO_1"><a name="DERIVED_SSS_SCL_SSS_GO_1" id="DERIVED_SSS_SCL_SSS_GO_1" role="button" onclick="javascript:cancelBubble(event);" href="javascript:submitAction_win1(document.win1,'DERIVED_SSS_SCL_SSS_GO_1');"><img src="https://sims-prd.sfu.ca/cs/csprd/cache/PT_NAV_GO_1.gif" name="DERIVED_SSS_SCL_SSS_GO_1$IMG" alt="Go" title="Go" border="0"></a><!-- DERIVED_SSS_SCL_SSS_GO_1 --></div>
</td>
</tr>

<tr>
<td height="22"></td>
<td align="left" valign="top">
<div id="win1divDERIVED_SSS_SCL_SSS_MORE_ACADEMICS"><select name="DERIVED_SSS_SCL_SSS_MORE_ACADEMICS" id="DERIVED_SSS_SCL_SSS_MORE_ACADEMICS" size="1" class="PSDROPDOWNLIST" style="width:132px; ">
<option value="">&nbsp;</option>
<option value="4010">Academic Planner</option>
<option value="3010">Academic Requirements</option>
<option value="2015">Apply/Cancel Graduation</option>
<option value="SFU4">Appointment Booking</option>
<option value="SFU5">Confirmation of Enrollment</option>
<option value="2050">Course History</option>
<option value="SFU7">Credential Completion Letter</option>
<option value="1002">Enrollment Activity</option>
<option value="1020">Exam Schedule</option>
<option value="SFU1">Link to SFU Canvas</option>
<option value="SFU2">Prev. Requested Reports</option>
<option value="SFU6">Transcript: Advising</option>
<option value="SFU3">Transcript: Official</option>
<option value="2035">Transcript: Unofficial</option>
<option value="2025">Transfer Credit: Report</option>
<option value="9999" selected="selected">other academic...</option>
</select></div>
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
</div>
</td>

推荐答案

尝试以下代码,看看它是否有效-

Try this code and lets see if it works-

 element = driver.find_element_by_id("DERIVED_SSS_SCL_SSS_GO_1")
 driver.execute_script("arguments[0].click();", element)

更新

element = driver.find_element_by_xpath('//*[@id="DERIVED_SSS_SCL_SSS_GO_1"]/img')
driver.execute_script("arguments[0].click();", element)

这篇关于Python Selenium按钮不会单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆