首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用selenium播放2048

使用selenium播放2048
EN

Stack Overflow用户
提问于 2016-07-13 20:02:55
回答 1查看 923关注 0票数 1

我已经编写了代码,将玩2048直到游戏结束,但有什么办法让selenium点击尝试再次按钮时,它弹出?

代码语言:javascript
复制
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

browser = webdriver.Chrome()
browser.get('https://gabrielecirulli.github.io/2048/')

grid = browser.find_element_by_tag_name('body')
direction = {0: Keys.UP, 1: Keys.RIGHT, 2: Keys.DOWN, 3: Keys.LEFT}
count = 0
browser.find_element_by_class_name('grid-container').click()
while True:
    count += 1
    grid.send_keys(direction[count % 4])
    try:
        WebDriverWait(browser, .00001).until(
            EC.presence_of_element_located((By.ID, "game-message game-over")))
        browser.find_element_by_class_name('game-over').click()
    except:
        print("OK")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-13 20:07:54

在快速地玩完游戏之后,重试按钮看起来是:

代码语言:javascript
复制
<a class="retry-button">Try again</a>

所以

代码语言:javascript
复制
browser.find_element_by_class_name('retry-button').click()

应该为你工作

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38360729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档