【问题标题】:I can not find the click event in href="#"我在 href="#" 中找不到点击事件
【发布时间】:2019-08-10 01:46:01
【问题描述】:

我正在浏览一个列表以单击 Alquilar 中的 Alquilar 按钮

<ul id="vertical-operation-menu">
  <li valorTipoHome="1" id="home-Venta" class="js-btn-home current vertical-operation-menu-btns">
    <a href="#">Comprar</a>
  </li>
  <li valorTipoHome="2" id="home-Alquiler" class="js-btn-home  vertical-operation-menu-btns">
    <a href="#">Alquilar</a>
  </li>
  <li valorTipoHome="desarrollosURL" id="home-Emprendimiento" class="js-btn-home  vertical-operation-menu-btns">
    <a href="#">Emprendimientos</a>
  </li>
  <li valorTipoHome="homeComercial_grupo_4" data-tipo-propiedad-dfp="4,5,10,8,45" id="home-Comercial" class="js-btn-home  vertical-operation-menu-btns">
    <a href="#">Comercial</a>
  </li>
  <li valorTipoHome="4" id="home-Vacacional" class="js-btn-home  vertical-operation-menu-btns">
    <a href="#">Temporal</a>
  </li>
</ul>

我正在通过以下方式使用 XPATH 捕获它

tipoOperacion = webdriver.find_element_by_xpath('//*[@id="home-Alquiler"]/a')
tipoOperacion.click()

但什么也没发生

查看我正在捕获的数据并返回按钮的名称

a = tipoOperacion.text
print(a)

酒精

但是我不能点击按钮

我添加了问题的答案 print(WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//a[text()='Alquilar']"))).text)

酒精

【问题讨论】:

  • 您是否尝试单击父元素而不是链接?
  • @Guy 我不调查,会怎么样?
  • tipoOperacion = webdriver.find_element_by_id('home-Alquiler')
  • @Guy 没用

标签: python selenium selenium-webdriver


【解决方案1】:

试试这个看看是否有帮助。

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//a[text()='Alquilar']"))).click()

注意: 使用以下导入

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

编辑:

from selenium.webdriver.common.action_chains import ActionChains
 element=driver.find_element_by_xpath("//a[text()='Alquilar']")
 ActionChains(driver).move_to_element(element).perform()

driver.execute_script("arguments[0].click();",driver.find_element_by_xpath("//a[text()='Alquilar']"))

【讨论】:

  • 您能否检查一下您的 html 中是否有 iframe 存在?
  • 没有 iframe
  • 如果可以的话可以分享一下网址吗?
  • 你能打印出值吗:print(WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//a[text()='Alquilar']"))).text)
  • @Sebastian : 检查编辑过的一个。可能 webdriver 点击不起作用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-15
  • 2014-08-24
  • 1970-01-01
  • 2013-07-14
  • 2019-10-21
  • 1970-01-01
相关资源
最近更新 更多