1

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

Here's the 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>

I've tried the following:

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()

Any help is appreciated. Thanks.

EDIT: 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>
Rubiks H
  • 35
  • 6

2 Answers2

1

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)

update

element = driver.find_element_by_xpath('//*[@id="DERIVED_SSS_SCL_SSS_GO_1"]/img')
driver.execute_script("arguments[0].click();", element)
Kapil
  • 397
  • 4
  • 6
  • I'm not getting an error. It's just not pressing the button. I added more HTML to the original post. Hopefully that helps. – Rubiks H Aug 30 '17 at 08:49
  • I get this error: selenium.common.exceptions.InvalidSelectorException: Message: Given xpath expression "//[@id="DERIVED_SSS_SCL_SSS_GO_1"]/img" is invalid: SyntaxError: The expression is not a legal expression. – Rubiks H Aug 30 '17 at 17:32
  • @RubiksH -- updated it again. Please try this. It should work now. – Kapil Aug 30 '17 at 19:33
  • I still get the same error. selenium.common.exceptions.InvalidSelectorException: Message: Given xpath expression "//[@id="DERIVED_SSS_SCL_SSS_GO_1"]/img" is invalid: SyntaxError: The expression is not a legal expression. – Rubiks H Aug 30 '17 at 21:48
  • @RubiksH - There is issue with single quotes and double quotes. Please try one more time. Just copy from here and paste it in your code. – Kapil Aug 31 '17 at 04:27
  • Yeah, that isn't the problem. When you first posted your update, I fixed the single quotes and double quotes on my own, so the error still persists. – Rubiks H Aug 31 '17 at 08:12
0
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

selector = "//a[@id='DERIVED_SSS_SCL_SSS_GO_1']"

Try this firstly:

element = WebDriverWait(driver, 5).until(
    EC.visibility_of_element_located((By.XPATH, selector))
)
element.click()

if it doesn't work, give this a chance:

element = WebDriverWait(driver, 5).until(
    EC.element_to_be_clickable((By.XPATH, selector))
)
element.click()
Burak Özdemir
  • 510
  • 8
  • 18