我正在浏览一个列表,以单击在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)
ALQUILAR
但是我不能单击按钮
我为问题添加了答案 print(WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,“ // a [text()='Alquilar']”))))。text)
ALQUILAR
答案 0 :(得分:0)
尝试一下是否有帮助。
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()
OR
driver.execute_script("arguments[0].click();",driver.find_element_by_xpath("//a[text()='Alquilar']"))