Skip to content

Commit

Permalink
Avoid find_x_by_css_selector
Browse files Browse the repository at this point in the history
  • Loading branch information
korakot committed May 6, 2022
1 parent 60a8cd6 commit 416481c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions kora/selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@
os.system('apt install chromium-chromedriver')
os.system('pip install selenium')
# set options to be headless, ..
from selenium import webdriver
options = webdriver.ChromeOptions()
from selenium.webdriver import Chrome, ChromeOptions
options = ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
# create a webdriver instance, ready to use
wd = webdriver.Chrome('chromedriver',options=options)
wd = Chrome('chromedriver',options=options)

# make it easier to query and explore elements
wd.select = wd.find_elements_by_css_selector
wd.select1 = wd.find_element_by_css_selector
from selenium.webdriver.remote.webelement import WebElement
WebElement.__str__ = lambda self: self.get_attribute('outerHTML')
WebElement.__repr__ = WebElement.__str__
WebElement.select = WebElement.find_elements_by_css_selector
WebElement.select1 = WebElement.find_element_by_css_selector
Chrome.select = WebElement.select = lambda self, v: self.find_elements('css selector', v)
Chrome.select1 = WebElement.select1 = lambda self, v: self.find_element('css selector', v)
WebElement.__getitem__ = WebElement.get_attribute

# show screenshot easily with _repr_png_
Expand All @@ -28,4 +26,4 @@ def _screen_shot(self):
tmp = TempFile(suffix='.png')
self.save_screenshot(tmp.name)
return tmp.read()
webdriver.Chrome._repr_png_ = _screen_shot
Chrome._repr_png_ = _screen_shot
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

setuptools.setup(
name="kora",
version="0.9.19",
version="0.9.20",
author="Korakot Chaovavanich",
author_email="korakot@gmail.com",
description="Convenient tools for Colab",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/airesearch-in-th/kora",
url="https://github.com/korakot/kora",
install_requires=requirements,
packages=setuptools.find_packages(),
classifiers=[
Expand Down

0 comments on commit 416481c

Please sign in to comment.