python - Selenium 和 python3 激活文本框而不输入值

标签 python python-3.x selenium

使用selenium和python3编写脚本,是否有可能让脚本单击http://digesto.asamblea.gob.ni/consultas/coleccion/上的文本框(单击“Búsqueda avanzada”)而不输入值,以便光标在该文本框中处于事件状态(通常由闪烁的垂直线指示),参见示例图片?

enter image description here

通常会使用

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

但这并没有给出预期的结果,因为文本框不是“事件的”,如下所示:

enter image description here

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

最佳答案

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

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/

相关文章:

python - 如何删除pyspeech windows语音识别命令?

python - 如何在 python 中创建一个给定 n 行和 k 列、起始数 x 和步长 y 的数组

java - 在输入速度非常慢时使用 64 位 Windows IE WebDriver

firefox - 如果我将注意力从 FireFox 窗口移开,为什么 Selenium Webdriver 测试会开始失败?

python - 新手 Python/正则表达式 : pull strings between <a> tags using regex

python - Python 中的 Hive 子字符串等效项

python - 如何在日志处理程序中指定 str.format() 样式?

python-3.x - OSError : 269892000 requested and 269188084 written

python - 在列表中排序列表

java - 在 selenium java 中断言颜色值是否正确