I've a problem in interacting with a website. For me it's the first time I used Python for doing such a thing. I want to write a code in order to play the game in this link: https://www.coolmathgames.com/0-worlds-hardest-game. I tried using this code to move the player inside the game, but the result is that the web page scrolls and the player doesn't move.
import random
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get('https://www.coolmathgames.com/0-worlds-hardest-game')
moves = [Keys.LEFT, Keys.DOWN, Keys.RIGHT, Keys.UP]
time.sleep(10)
i = 0
while i < 100:
time.sleep(0.1)
driver.find_element_by_css_selector('html').send_keys(random.choice(moves))
i += 1
(The time.sleep(10) instruction is inserted in order to allow me to manually enter in the game)
Which is the code to use to interact with the game and not only with the website page?
Aucun commentaire:
Enregistrer un commentaire