【问题标题】:selenium python cannot send number as key for inputselenium python 无法将数字作为输入键发送
【发布时间】:2020-08-14 10:15:59
【问题描述】:

我尝试将电话号码发送到下面的输入元素

<div id="mainframe.childframe.form.div_main.form.div_work.form.edt_mbtlTelNoCentral" class="Edit" tabindex="-1" style="left:309px;top:305px;width:85px;height:28px;" aria-label="휴대전화 가운데자리(필수입력) " aria-description="" userstatus="" status="enabled"><input id="mainframe.childframe.form.div_main.form.div_work.form.edt_mbtlTelNoCentral:input" class="nexainput" style="left:0px;top:0px;width:83px;height:26px;ime-mode:disabled;" value="" maxlength="4" type="text"><input id="mainframe.childframe.form.div_main.form.div_work.form.edt_mbtlTelNoCentral:input" class="nexainput" style="left:0px;top:0px;width:83px;height:26px;ime-mode:disabled;" value="" maxlength="4" type="text"></div>

使用此代码

actions = ActionChains(driver)
ele = driver.find_element_by_xpath('//*[@maxlength="4"]')
actions.click(ele).key_down(Keys.CONTROL).send_keys("a").key_up(Keys.CONTROL).send_keys("Keys.Delete").send_keys('9049').perform()

但它保持这样的发送密钥 enter image description here

我该如何解决这个问题?

【问题讨论】:

  • 您是否尝试过直接将密钥发送到元素? ele.send_keys("9049")
  • @BendikKnapstad 是的,但没用
  • 你想使用哪个页面?
  • @BendikKnapstadhttps://www.ehaneul.go.kr:5443/esky_p/esky_index.jsp#MENU:M211002000 这里是韩国网站
  • 抱歉,页面要我下载一些东西。这不会发生

标签: python python-3.x selenium web web-crawler


【解决方案1】:

假设我找对了地方(即使使用 Google 翻译,我的韩语也达不到标准),我相信您有两个匹配 xpath "//*[@maxlength="4"]" 的框。

我创建了这个例子来填充它们:

#get elements matching your xpath; this will return 2 items
elems = driver.find_elements_by_xpath('//*[@maxlength="4"]')

#to fill both boxes
numbers=[1234,5678] 
for i, num in enumerate(numbers):
    elems[i].clear()
    elems[i].send_keys(num)

【讨论】:

  • 非常感谢兄弟!
猜你喜欢
  • 2020-11-30
  • 1970-01-01
  • 2021-08-29
  • 2022-01-14
  • 1970-01-01
  • 2017-06-02
  • 2019-10-20
  • 2021-09-18
  • 1970-01-01
相关资源
最近更新 更多