-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrowser.py
More file actions
47 lines (39 loc) · 1.78 KB
/
Browser.py
File metadata and controls
47 lines (39 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import NoSuchElementException
import os
class Browser:
def __init__(self):
self.driver = self.getChromeDriver()
def getChromeDriver(self):
chromedriver = "/usr/local/bin/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
chrome_options = Options()
# This make Chromium reachable
chrome_options.add_argument("--no-sandbox")
# Overrides default choices
chrome_options.add_argument("--no-default-browser-check")
chrome_options.add_argument("--disable-user-media-security=true")
chrome_options.add_argument("--use-fake-ui-for-media-stream")
return webdriver.Chrome(chromedriver, chrome_options=chrome_options)
def elementExists(self, cssSelector):
try:
self.driver.find_element_by_css_selector(cssSelector)
except NoSuchElementException:
return False
return True
def reveal(self, row, col):
cellCssId = str(row+1) + '_' + str(col+1)
cell = self.driver.find_element_by_id(cellCssId)
ActionChains(self.driver).click(cell).perform()
print('Revealing sqaure ' + cellCssId)
def flag(self, row, col):
cellCssId = str(row+1) + '_' + str(col+1)
cell = self.driver.find_element_by_id(cellCssId)
ActionChains(self.driver).context_click(cell).perform()
print('Flaging sqaure ' + cellCssId + ' as bomb')
def restartGame(self):
cell = self.driver.find_element_by_id('face')
ActionChains(self.driver).click(cell).perform()
print(os.linesep + 'Bad luck, restarting...' + os.linesep)