简体   繁体   中英

selenium python cannot send number as key for input

i tried to send phone numbers to input element below

<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>

with this code

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()

but it keep send key like this enter image description here

how can i fix this?

Assuming I am looking in the right place (my Korean is not up to scratch even with Google Translate), I believe you have two boxes matching xpath "//*[@maxlength="4"]".

I have created this example to fill both of them:

#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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM