代码之家  ›  专栏  ›  技术社区  ›  Til Hund

Selenium和python3在不输入值的情况下激活文本框

  •  1
  • Til Hund  · 技术社区  · 7 年前

    http://digesto.asamblea.gob.ni/consultas/coleccion/ (单击“Bsqueda avanzada”)而不输入值,以便光标在该文本框中处于活动状态(通常由闪烁的垂直线指示),参见示例图片?

    enter image description here

    通常人们会使用

    driver.find_elements_by_xpath('//*[@id="txtCaptcha"]').click()

    enter image description here

    我的想法是让脚本“激活”文本框并等待我插入验证码,这样我就可以开始写作,而不是每次自己点击文本框。

    1 回复  |  直到 7 年前
        1
  •  3
  •   Andersson    7 年前

    您可以等待元素可单击,然后单击它:

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'txtCaptcha'))).click()