Search code examples
seleniumselenium-webdriverclickwebdriverwaitexpected-condition

AttributeError: 'WebElement' object has no attribute 'Click' error trying to Click on a link using Selenium Python


So I am in the process of trying to reach a search page which involves clicking on a clickable link on the bottom of the page. My code seems to be able to find the link or at least not throw an error when attempting to, however I get the error "AttributeError: 'WebElement' object has no attribute 'Click'" even though the element is physically clickable on the page. Here is the code and website.

driver = webdriver.Edge(r'C:/Users/User/Desktop/Anaconda/edgedriver_win32/msedgedriver')
driver.get("https://www.canada.ca/en/environment-climate-change/services/species-risk-public-registry/cosewic-assessments-status-reports")
#click on the "Search COSEWIC status reports" button
element = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.LINK_TEXT, "Search COSEWIC status reports"))
)
link = driver.find_element_by_link_text("Search COSEWIC status reports");
link.Click();

If I am wrong about this element being clickable please let me know. To be clear I am trying to click on the link "Search COSEWIC status reports found at the bottom of the webpage "https://www.canada.ca/en/environment-climate-change/services/species-risk-public-registry/cosewic-assessments-status-reports"

Update

I have found a workaround but the question still remains. I have run into another attribute that needs clicking and it doesn't seem to have attributes 'id' or anything easy to identify by.

<span data-v-7ee3c58f="" class="name-primary">COSEWIC Status Appraisal Summary on the Pacific Water Shrew <em>Sorex bendirii</em> in Canada</span>

I have tried copying the XPath to this element and the id within the XPath but they don't seem to work. this is the first result on the page. "https://species-registry.canada.ca/index-en.html#/documents?documentTypeId=18&sortBy=documentTypeSort&sortDirection=asc&pageSize=10&keywords=pacific%20water%20shrew"


Solution

  • Your language bing is so instead of Click() you need to use click()

    Additionally, to click on a clickable element instead of presence_of_element_located() you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

    driver = webdriver.Edge(r'C:/Users/User/Desktop/Anaconda/edgedriver_win32/msedgedriver')
    driver.get("https://www.canada.ca/en/environment-climate-change/services/species-risk-public-registry/cosewic-assessments-status-reports")
    #click on the "Search COSEWIC status reports" button
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, "Search COSEWIC status reports"))).click()