【问题标题】:Hidden checkbox into button without id using Selenium in Python在Python中使用Selenium将复选框隐藏到没有ID的按钮中
【发布时间】:2021-02-24 09:48:12
【问题描述】:

我想点击隐藏在按钮中的复选框,我快疯了。 HTML 代码如下:

enter image description here

我要做的是选择按钮并使用代码选中框

driver.find_element_by_xpath('//*[@id="frmBusquedajurisprudencia"]/div[3]/div[1]/div[1]/div/ul/li[1]/a/label/input').click()

并返回 ElementNotInteractableException:消息:元素不可交互。

我的假设是,复选框是隐藏的(不在 DOM 中),所以我必须首先单击按钮,然后单击复选框,但我不确定它是如何完成的。

我的第二个假设是 input 的元素不可点击,我宁愿关注 li 元素,因为当我检查 bpx 时 li 的类呈现“活动”。

非常感谢所有答案。

【问题讨论】:

标签: javascript python html selenium screen-scraping


【解决方案1】:

要简单地打开元素,请单击带有多选标签的按钮,然后单击输入值为 CIVIL 的标签。

wait = WebDriverWait(driver, 30)
driver.get('https://www.poderjudicial.es/search/indexAN.jsp')
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button.close"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH,"(//button[@class='multiselect dropdown-toggle btn btn-default tooltips'])[1]"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH,"//label[.//input[@value='CIVIL']]"))).click()

导入

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-19
    • 1970-01-01
    • 1970-01-01
    • 2021-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多