0

I am trying to click on the following button using Selenium in Python. However, any way I have tried to approach clicking on that button has failed and I was hoping someone could help. For all intents and purposes. I am a novice in both Python/Selenium so any help would be greatly appreciated!

<tr> 
  <td colspan=3></td>
  <td align=center valign='center'> <a href="javascript:myFunction('/mailbox/jsp/MBIList.jsp')"
      onMouseOver="chgButton('Go','GoOver'); window.status=''; return true;"
      onMouseOut="chgButton('Go','GoOff'); window.status=''; return true;"
      onMouseDown="chgButton('Go','GoDown'); return true;"><img border=0
      src="/mailbox/images/go_off.gif" vspace=7 name='Go' align='top'></a> 
  </td>
</tr>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
yms111
  • 1
  • Welcome to SO. Please share what all methods you have tried. It will be easy to see issue if you share your code rather than guessing it. – rahul rai Aug 26 '20 at 12:55

2 Answers2

0

U can click on any element using any of the element attributes. For example in this case I would use attribute @name='Go' in your Xpath, where you are trying to select element.

danoblinux
  • 56
  • 7
0

The desired element is a dynamic element, so to click on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href*='/mailbox/jsp/MBIList'] > img[name='Go'][src^='/mailbox/images/go_off']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(@href, '/mailbox/jsp/MBIList')]/img[@name='Go' and starts-with(@src, '/mailbox/images/go_off')]"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you! Am getting the same timeout error: selenium.common.exceptions.TimeoutException: Message: – yms111 Aug 26 '20 at 19:55
  • @yms111 To address [TimeoutException](https://stackoverflow.com/questions/48916783/python-selenium-chromedriver-timeoutexception/48920865#48920865) check [this](https://stackoverflow.com/questions/63014684/selenium-common-exceptions-timeoutexception-error-using-webdriverwait-with-expec/63020121#63020121) and [this](https://stackoverflow.com/questions/50843483/selenium-common-exceptions-timeoutexception-while-invoking-click-on-an-elemen/50853898#50853898) discussion. – undetected Selenium Aug 27 '20 at 08:15