2

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"

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Max Duso
  • 305
  • 1
  • 4
  • 15
  • Which programming language you are using. If its python, you don't need `semi-colon` and to click its `click()` with small letters. – pmadhu Nov 30 '21 at 01:57

1 Answers1

1

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()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Oh interesting, it seems there are a few different syntax things to look out for over selenium. Thanks for that. As for as the selection goes, the element I want to click now is this. `COSEWIC Status Appraisal Summary on the Pacific Water Shrew Sorex bendirii in Canada` I have tried by link text and partial link text also by class name as that is present although there are two with the same name and I cant seem to index the first one with `[0]`. I don't understand XPath or CSS though I have tried copying XPath. Didn't work – Max Duso Nov 30 '21 at 18:37