首页 > 解决方案 > Selenium Can't find "HOME" element on Facebook

问题描述

I'm doing some exercises with selenium, trying to scrape a few pages on facebook. However, I'm not able to find the "Home" button link element to keep going. This on the left menu in any user's profile.

enter image description here

From what I'm seeing in the page code, the link is here:

<div class="_2yaa" data-key="tab_home">
  <a class="_2yau" data-endpoint="/seudogshow/?ref=page_internal" href="/seudogshow/?ref=page_internal">
    <span class="_2yav">Home</span>
    <span class="img _55ym _55yn _55yo _2wwb" aria-busy="true" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuetext="Loading..."></span>
  </a>
</div>

How would you guys go about clicking this button?

I tried with something like this:

driver.find_element_by_xpath("//a[contains(text(), 'Home')]").click()

or

wait.until(EC.element_to_be_clickable((By.XPATH, "//a[contains(text(), 'Home')]"))).click()

But I'm clearly doing it wrong.

标签: pythonseleniumselenium-chromedriver

解决方案


您尝试单击的元素有一个span标签,而不是a. 尝试以下操作:

driver.find_element_by_xpath("//span[contains(text(), 'Home')]").click()


推荐阅读