【问题标题】:Send Keys to Game Container 2048将密钥发送到游戏容器 2048
【发布时间】:2020-06-29 04:53:07
【问题描述】:

我正在尝试将密钥发送到 2048,并且我正在尝试等到找到游戏容器元素然后将密钥发送给它。由于某种原因 selenium 无法找到游戏容器。我假设这与关注正确的元素有一些问题,但我无法弄清楚。

WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.XPATH, r'/html/body/div[1]/div[4]'))).send_keys(Keys.UP)

这会引发超时异常,因为它无法找到游戏容器。 有人可以帮我将箭头键发送到 2048 吗?我在https://play2048.co/

【问题讨论】:

    标签: python html automation selenium-chromedriver


    【解决方案1】:

    试试看:

    from selenium.webdriver.common.keys import Keys
    import random
    import time
    
    moves = [Keys.LEFT, Keys.DOWN, Keys.RIGHT, Keys.UP]
    while True:
        driver.find_element_by_css_selector('body').send_keys(random.choice(moves))
        time.sleep(2)
    

    python: How can I press arrow keys randomly selenium

    【讨论】:

    • 无限乍得上帝保佑!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-07
    • 2020-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多