selenium python 无法发送数字作为输入键
selenium python cannot send number as key for input
我尝试将 phone 个数字发送到下面的输入元素
<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
我该如何解决这个问题?
假设我找对了地方(即使使用 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)
我尝试将 phone 个数字发送到下面的输入元素
<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
我该如何解决这个问题?
假设我找对了地方(即使使用 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)