# selenium dummy based on seledroid, generated by the termux package python-selenium-is-seledroid
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):
    self.__prepare()
    return dir(self.__original)
  def __getattr__(self, name):
    self.__prepare()
    try:
      value = getattr(self.__original, name)
    except AttributeError:
      if name.endswith("Options"):
        value = DummyOptions
      elif name[:1].isupper():
        value = self.__original.Chrome
      else:
        raise
    return value

# ====== selenium.webdriver ======
webdriver = SeleniumDummyWebdriverModule("selenium.webdriver")
sys.modules["selenium.webdriver"] = webdriver

# ========== Keys.RETURN ==========
from selenium.webdriver.common.keys import Keys
Keys.RETURN = Keys.ENTER

# ======= selenium.common ========
import selenium.webdriver.common as common
sys.modules["selenium.common"] = common

# == selenium.common.exceptions ==
import selenium.webdriver.common.exception as exceptions
sys.modules["selenium.common.exceptions"] = exceptions
common.exceptions = exceptions


