I am trying to automate clicking on a button of a webpage where the source code has the following structure:

<div id="ctl02_" class="sel">
   <div id="Lo" class="cont">       
      <div class="cl">         
         <span onclick="__doPostBack('ct$ctl00','M_CC_1')" 
           class="fakeLink" title="add &quot;D&quot;"> 
           <img src="Skin/D.png" alt="add &quot;D&quot;" class="io" 
           />&nbsp;D</span> <br />

I am currently trying to accomplish this with the use of python and Selenium. Below you can find how I am trying to do this:

driver = webdriver.Firefox()
driver.wait = WebDriverWait(driver, 5)

   elem = driver.wait.until(EC.presence_of_element_located((By.XPATH, "//div[@class='cl']")))

except TimeoutException:
    print("Element not found")


The program finishes fine (exit code 0), however, the webdriver has not moved to the webpage behind the click (which I would encounter if I would physically click on the button D on the webpage). I have tried many things giving me the feeling that I am missing something basic here.

Where am I going wrong here? Am I using Selenium in a wrong way here? Or is Selenium not the right tool for this?

  • No exception at all?
    – Yu Zhang
    Aug 11, 2016 at 2:34

2 Answers 2


The only problem in your Selenium script is that you are clicking on the div that contains the link and not the link that really needs to be clicked.

Change your code from,

elem = driver.wait.until(EC.presence_of_element_located((By.XPATH, "//div[@class='cl']")))


elem = driver.wait.until(EC.presence_of_element_located((By.XPATH, "//span[@class='fakeLink']")))

and check.

Make the code click the **<span>** tag which has the **onClick** event you want executed.

The **<div>** tag you're clicking at present with your Selenium script doesn't have the **onClick** event that has to be executed for the redirection.


Do you try to click a span? Maybe <div> is bigger than <span> and Selenium click on area that doesn't bind to link behind.

<span onclick="__doPostBack('ct$ctl00','M_CC_1')" 
      class="fakeLink" title="add &quot;D&quot;"> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.