首页 > 解决方案 > 无法使用 selenium python 发送密钥

问题描述

元素

<input id="mainframe.childframe.form.div_main.form.div_work.form.edt_applicantMgmtName:input" class="nexainput" style="left:0px;top:0px;width:173px;height:26px;" value="예: 홍길동" type="text" data-security="on" tk_security="true">

我的代码

driver.find_element_by_xpath('//input[@value="예: 홍길동"]').send_keys(name)

但它只点击元素。和元素看起来像这样

在此处输入图像描述

在此处输入图像描述

我应该怎么办?

标签: pythonpython-3.xseleniumwebweb-crawler

解决方案


尝试清除 webElement,然后在文本字段中发送字符序列。

ele.clear()
ele.sendkeys("text to send")

如果这不起作用,请尝试使用 ActionChains 通过键盘操作执行鼠标和键盘操作 - 单击、Ctrl + A、删除,然后发送字符序列。像这样的东西:

actions = ActionChains(driver)
actions.click(ele).key_down(Keys.CONTROL).send_keys("a").key_up(Keys.CONTROL).send_keys("Keys.Delete").send_keys("your-text").perform

推荐阅读