Skip to content

Instantly share code, notes, and snippets.

@joshdabosh
Created March 30, 2020 18:23
Show Gist options
  • Save joshdabosh/482e9ac9a648689669ccb60d415767ad to your computer and use it in GitHub Desktop.
Save joshdabosh/482e9ac9a648689669ccb60d415767ad to your computer and use it in GitHub Desktop.
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
import requests
def is_prime(n):
if n == 1:
return False
for i in range(2, int(n**0.5)+1):
if n % i == 0:
return 0
i += 1
return 1
browser = webdriver.Chrome(ChromeDriverManager().install())
browser.get("https://isthisprime.com/game")
button = browser.find_element_by_xpath('//button[@id="start"]')
button.click()
while True:
try:
n = int(browser.find_element_by_xpath('//span[@id="n"]').text)
except ValueError:
break
if is_prime(n):
browser.find_element_by_css_selector('body').send_keys(Keys.LEFT)
else:
browser.find_element_by_css_selector('body').send_keys(Keys.RIGHT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment