python - 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.
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.
解决方案
您尝试单击的元素有一个span
标签,而不是a
. 尝试以下操作:
driver.find_element_by_xpath("//span[contains(text(), 'Home')]").click()
推荐阅读
- events - 如何在 servicenow 的日历中查看事件“我的日程安排”
- c++ - 访问旧堆栈帧
- c# - 如何在 Visual Basic 中从 C# 转换对象
- jquery - 在动态表上对 Jquery Datatable 进行自定义排序
- javascript - 如何在 reactjs 中有一个粘性导航栏
- c# - 多流TCP c#
- qt - 如何修改 Qt 标签中的文本?
- docker - 如何连接在不同网络上运行的不同 docker 容器
- python - 'datetime.date' 对象在使用 timedelta 时没有属性 'days' 错误
- javascript - 如何在不使用 eval() 或窗口的情况下将字符串转换为 javascript 中的变量?