Python code to click on anchor tag
Question: I am writing a python code to automate a web page. I need to click on play
button to play the recording. But I am not able to do so through the code.

**Inspect element gives me this - outer HTML of 'play' :**

    
    
    <div class="play">
    <a id="sm_1855464769" class="sm2_button" href="#"> </a>
    </div>
    

**Inspect element gives me this - Xpath of 'play' :**

    
    
    //*[@id="recording_1855464769"]/div/div/div[8]
    

**The python code what i wrote is :**

    
    
    element = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located(EC.find_element_by_xpath("//*[@id='recording_1855464769']/div/div/div[8]"))
    element.click()
    

**Error message what I get in the terminal :**

    
    
    element = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located(EC.find_element_by_xpath("//*[@id='recording_1855464769']/div/div/div[8]")))
    AttributeError: 'module' object has no attribute 'find_element_by_xpath'
    

I need to click on the anchor tag in order to play the audio. How can I do
that ?? Plz help..


Answer: You need to use `By`. Replace `EC.find_element_by_xpath` with `By.XPATH`.

    
    
    from selenium.webdriver.common.by import By    
    
    element = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located
                  (By.XPATH("//*[@id='recording_1855464769']/div/div/div[8]"))
    

