-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
python-selenium-is-seledroid: fix bug of python selenium.webdriver.su…
…pport.expected_conditions (#481)
- Loading branch information
1 parent
c6d2d97
commit 8877bb3
Showing
2 changed files
with
31 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,54 @@ | ||
# selenium dummy based on seledroid, generated by the termux package python-selenium-is-seledroid | ||
import sys, types | ||
|
||
class DummyOptions: | ||
def add_argument(self, arg): | ||
pass | ||
|
||
webdriver_original = None | ||
|
||
def get_webdriver_original(): | ||
global webdriver_original | ||
if webdriver_original is None: | ||
import seledroid.webdriver as webdriver_original | ||
|
||
class AdaptedSeledroidChrome(webdriver_original.Chrome): | ||
def __init__(self, *args, options=None, **kwargs): | ||
return super().__init__(*args, **kwargs) | ||
|
||
webdriver_original.Chrome = AdaptedSeledroidChrome | ||
return webdriver_original | ||
import sys, types, os | ||
if not os.path.exists("/data/app/com.luanon.chromium-1"): | ||
raise ImportError("Seledroid APP not installed, run `install-seledroid-app` for that") | ||
|
||
class SeleniumDummyWebdriverModule(types.ModuleType): | ||
def __prepare(self): | ||
if "__original" in self.__dict__: | ||
return | ||
import seledroid.webdriver as original | ||
class Chrome(original.Chrome): | ||
def __init__(self, *args, options=None, gui=False, **kwargs): | ||
return super().__init__(*args, gui=gui, **kwargs) | ||
class DummyOptions: | ||
def add_argument(self, arg): | ||
pass | ||
original.Chrome = Chrome | ||
original.DummyOptions = DummyOptions | ||
self.__original = original | ||
self.__dict__["__original"] = original | ||
def __dir__(self): | ||
webdriver = get_webdriver_original() | ||
dir_value = dir(webdriver) | ||
return dir_value | ||
|
||
def __getattribute__(self, name): | ||
webdriver = get_webdriver_original() | ||
self.__prepare() | ||
return dir(self.__original) | ||
def __getattr__(self, name): | ||
self.__prepare() | ||
try: | ||
value = getattr(webdriver, name) | ||
value = getattr(self.__original, name) | ||
except AttributeError: | ||
if name.endswith("Options"): | ||
value = DummyOptions | ||
elif name[:1].isupper(): | ||
value = webdriver.Chrome | ||
value = self.__original.Chrome | ||
else: | ||
raise | ||
return value | ||
|
||
# convert this into a selenium dummy package | ||
import seledroid | ||
__package__ = "selenium" | ||
__path__ = seledroid.__path__ | ||
|
||
# ====== selenium.webdriver ====== | ||
sys.modules["selenium.webdriver"] = webdriver = SeleniumDummyWebdriverModule("selenium.webdriver") | ||
webdriver = SeleniumDummyWebdriverModule("selenium.webdriver") | ||
sys.modules["selenium.webdriver"] = webdriver | ||
|
||
# ========== Key.RETURN ========== | ||
# ========== Keys.RETURN ========== | ||
from selenium.webdriver.common.keys import Keys | ||
Keys.RETURN = Keys.ENTER | ||
|
||
# ======= selenium.common ======== | ||
import seledroid.webdriver.common as common | ||
import selenium.webdriver.common as common | ||
sys.modules["selenium.common"] = common | ||
|
||
# == selenium.common.exceptions == | ||
import seledroid.webdriver.common.exception as exceptions | ||
import selenium.webdriver.common.exception as exceptions | ||
sys.modules["selenium.common.exceptions"] = exceptions | ||
common.exceptions = exceptions | ||
|
||
|