gpt4 book ai didi

python-3.x - python : How can I press arrow keys randomly selenium

转载 作者:行者123 更新时间:2023-12-01 12:23:17 24 4
gpt4 key购买 nike

我正在尝试制作一个播放 2048 的程序通过随机选择箭头键。

我试过这样的事情:

 moves = [htmlElem.send_keys(Keys.UP),htmlElem.send_keys(Keys.RIGHT),htmlElem.send_keys(Keys.DOWN),htmlElem.send_keys(Keys.LEFT)]


while True:
random.choice(moves)

这是行不通的。我试过 print(random.choice(moves)) ,但它无限循环 None
那么如何使用 Selenium 随机按下箭头键呢?

最佳答案

这似乎有效。试试吧,让我知道结果:

from selenium.webdriver.common.keys import Keys
import random

moves = [Keys.LEFT, Keys.DOWN, Keys.RIGHT, Keys.UP]
while True:
driver.find_element_by_css_selector('body').send_keys(random.choice(moves))

关于python-3.x - python : How can I press arrow keys randomly selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42060724/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com