Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
296 views
in Technique[技术] by (71.8m points)

python - How to type like a Human via ActionChains key_down, key_up

I am making an online automation program. Unfortunately, however, this site checks the user's input speed.

The site reports an error message due to two reasons: the speed at which the key is pressed and the speed at which the key is pressed. Therefore, the commonly used send_keys are not available. This is because the key_up speed is displayed as 0 when debugging.

To solve this problem, it seems necessary to adjust the speed of input like a person. So I tried the following.

ac = ActionChains(driver)
ac.key_down("a")
ac.perform()
Sleep(0.010, 0.05)

ac = ActionChains(driver)
ac.key_up("a")
ac.perform()
Sleep(0.010, 0.05)

I would appreciate if you could tell me a better way.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you can loop through string :

for i in "somehting fad a":
    time.sleep(1)
    elem.send_keys(i)

If that doesn't work try :

for i in "This is a test":
    action = ActionChains(driver)
    action.key_down(i).pause(1).key_up(i).perform()
    time.sleep(1)

There is pause method within action class that pauses next action in the chain


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...