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

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

所以我正在尝试访问一个搜索页面,该页面涉及点击页面底部的可点击 link。我的代码似乎能够找到 link 或者至少在尝试时不会抛出错误,但是我收到错误“AttributeError:'WebElement' object has no attribute 'Click'”,即使该元素在页面上是可物理点击的。 这是代码和网站。

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();

如果我对这个元素可点击的看法有误,请告诉我。明确地说,我正在尝试单击 link“在网页底部找到的搜索 COSEWIC 状态报告”https://www.canada。ca/en/environment-climate-change/services/species-risk-public-registry/cosewic-assessments-status-reports“

更新

我找到了解决方法,但问题仍然存在。 我有 运行 到另一个需要点击的属性,它似乎没有属性 'id' 或任何容易识别的东西。

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

我已经尝试将 XPath 复制到此元素和 XPath 中的 id,但它们似乎不起作用。这是页面上的第一个结果。 "https://species-registry.canada.ca/index-en.html#/documents?documentTypeId=18&sortBy=documentTypeSort&sortDirection=asc&pageSize=10&keywords=pacific%20water%20shrew"

您的语言 bing 是 so instead of Click() you need to use

此外,点击 可点击的 元素而不是 you need to induce WebDriverWait for the and you can use either of the following :

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()