使用selenium和python3编写脚本,是否有可能让脚本单击http://digesto.asamblea.gob.ni/consultas/coleccion/上的文本框(单击“Búsqueda avanzada”)而不输入值,以便光标在该文本框中处于事件状态(通常由闪烁的垂直线指示),参见示例图片?
通常会使用
driver.find_elements_by_xpath('//*[@id="txtCaptcha"]').click()
但这并没有给出预期的结果,因为文本框不是“事件的”,如下所示:
我的想法是让脚本“激活”文本框并等待我插入验证码,这样我就可以开始编写而不是每次自己点击文本框。
最佳答案
您可以等待元素可点击,然后单击它:
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()
关于python - Selenium 和 python3 激活文本框而不输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54183227/