Clean up open-coded driver startup
This commit is contained in:
parent
3df6155547
commit
eb6fd8ac1d
1 changed files with 10 additions and 8 deletions
18
bidi.py
18
bidi.py
|
|
@ -16,6 +16,12 @@ logger = logging.getLogger(__name__)
|
||||||
# https://w3c.github.io/webdriver/#dfn-find-elements
|
# https://w3c.github.io/webdriver/#dfn-find-elements
|
||||||
EL_ID = 'element-6066-11e4-a52e-4f735466cecf'
|
EL_ID = 'element-6066-11e4-a52e-4f735466cecf'
|
||||||
|
|
||||||
|
DRIVERS = {
|
||||||
|
"chromium": "chromedriver",
|
||||||
|
# TODO: not packaged, get from https://github.com/mozilla/geckodriver/releases
|
||||||
|
"firefox": "/tmp/geckodriver",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class WebdriverError(RuntimeError):
|
class WebdriverError(RuntimeError):
|
||||||
pass
|
pass
|
||||||
|
|
@ -58,14 +64,10 @@ class WebdriverBidi:
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
if browser == 'chromium':
|
try:
|
||||||
# add --verbose for debugging
|
self.driver = subprocess.Popen([DRIVERS[browser], "--port=" + str(self.webdriver_port)])
|
||||||
self.driver = subprocess.Popen(["chromedriver", "--port=" + str(self.webdriver_port)])
|
except KeyError as e:
|
||||||
elif browser == 'firefox':
|
raise ValueError(f"unknown browser {browser}") from e
|
||||||
# TODO: not packaged, get from https://github.com/mozilla/geckodriver/releases
|
|
||||||
self.driver = subprocess.Popen(["/tmp/geckodriver", "--port", str(self.webdriver_port)])
|
|
||||||
else:
|
|
||||||
raise ValueError(f"unknown browser {browser}")
|
|
||||||
|
|
||||||
req = urllib.request.Request(
|
req = urllib.request.Request(
|
||||||
f"{self.webdriver_url}/session",
|
f"{self.webdriver_url}/session",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue