1. 程式人生 > >python編程快速上手之第10章實踐項目參考答案(11.11.3)

python編程快速上手之第10章實踐項目參考答案(11.11.3)

name driver ret text rul from url .get right

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Firefox()
url = https://gabrielecirulli.github.io/2048/
browser.get(url)
game_ele = browser.find_element_by_class_name(game-container)
while True:
    retry_ele = browser.find_element_by_class_name(
retry-button) # new game if retry_ele.text == Try again: retry_ele.click() game_ele = browser.find_element_by_class_name(game-container) game_ele.send_keys(Keys.UP) game_ele.send_keys(Keys.RIGHT) game_ele.send_keys(Keys.DOWN) game_ele.send_keys(Keys.LEFT)

python編程快速上手之第10章實踐項目參考答案(11.11.3)