【问题标题】:Element <a class="active" href="javascript:void(0);"> is not clickable at point (x,y ) because another element <span> obscures it [duplicate]元素 <a class="active" href="javascript:void(0);"> 在点 (x,y ) 处不可点击,因为另一个元素 <span> 遮住了它 [重复]
【发布时间】:2020-06-10 23:12:05
【问题描述】:

我正在尝试找到一个按钮,其中包含快速移动作为内容。

<li>
<a href="javascript:void(0);" class="active">
                            94 Quick Move-In Homes
<span class="len-tip-item bottom">
<i class="far fa-info-circle"></i> 
<span class="len-tip-box" style="display: none;">
An inventory home that is either under construction or completed.
</span></span></a></li>

我的代码如下所示。

driver.implicitly_wait(30)

python_button = driver.find_element_by_xpath("//a[contains(., 'Move-In')]")
python_button.click() #click link

我不确定为什么会出现此错误: ElementClickInterceptedException:消息:元素在点 (1257,736) 处不可点击,因为另一个元素遮住了它

【问题讨论】:

标签: python selenium selenium-webdriver web-scraping beautifulsoup


【解决方案1】:

在尝试点击之前,您需要等待并等待元素可点击。

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By    
from selenium.webdriver.support import expected_conditions as EC

driver.implicitly_wait(30)
python_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(., 'Move-In')]")))
python_button.click() #click link

您也可以使用等待等待其他预期条件。你可以在这里找到更多信息:https://selenium-python.readthedocs.io/waits.html

【讨论】:

  • 但现在它给了我这个错误:"TypeError: __init__() 需要 2 个位置参数,但在 "//a[contains(., 'Move-In')]"处给出了 3 个参数"
  • 我在一行的末尾缺少了一个 )。我已经更新了我的答案。
  • 实际上,我之前确实修复了这个错误,但它仍然给我这个错误
  • 我没有在我的笔记本电脑前尝试它,但已经更正了语法。您不应再收到类型错误。
猜你喜欢
  • 2018-08-21
  • 2021-08-03
  • 2021-07-27
  • 2020-02-03
  • 1970-01-01
  • 2019-07-05
  • 1970-01-01
  • 2018-12-19
相关资源
最近更新 更多