Skip to content

Commit

Permalink
Bump Selenium to 4.10.0.
Browse files Browse the repository at this point in the history
Selenium 4 removes the deprecated signatures and methods still used by
the Vectorizer (mozilla#308), and Selenium 3 is incompatible
with newer versions of Firefox, so we can't pin to the older version.

With this commit, `fathom train [...] --ruleset [...] --trainee [...]`
prints metrics and per-tag results again! \o/
  • Loading branch information
linabutler committed Jun 28, 2023
1 parent 70f902e commit d126115
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
38 changes: 20 additions & 18 deletions cli/fathom_web/vectorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from filelock import FileLock
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException, NoSuchWindowException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select

from .utils import read_chunks, samples_from_dir
Expand Down Expand Up @@ -398,23 +399,24 @@ def running_firefox(fathom_fox, show_browser, geckodriver_path):
"""
print('Running Firefox...', end='', flush=True)
options = webdriver.FirefoxOptions()
options.headless = not show_browser

with TemporaryDirectory() as download_dir:
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.dir', download_dir)
profile.set_preference('browser.cache.disk.enable', False)
profile.set_preference('browser.cache.memory.enable', False)
profile.set_preference('browser.cache.offline.enable', False)
profile.set_preference('devtools.chrome.enabled', True)

firefox = webdriver.Firefox(
options = webdriver.FirefoxOptions()
options.headless = not show_browser
options.set_preference('browser.download.folderList', 2)
options.set_preference('browser.download.dir', download_dir)
options.set_preference('browser.cache.disk.enable', False)
options.set_preference('browser.cache.memory.enable', False)
options.set_preference('browser.cache.offline.enable', False)
options.set_preference('devtools.chrome.enabled', True)

service = webdriver.firefox.service.Service(
executable_path=str(geckodriver_path.resolve()),
log_path=devnull,
)
firefox = webdriver.Firefox(
service=service,
options=options,
firefox_profile=profile,
service_log_path=devnull,
)

firefox.install_addon(str(fathom_fox), temporary=True)
Expand Down Expand Up @@ -466,7 +468,7 @@ def run_vectorizer(firefox, trainee_id, sample_filenames, output_path, kind_of_s
"""
def put_into_field(field_id, string):
"""Put a given string into the text field of a given ID."""
field = firefox.find_element_by_id(field_id)
field = firefox.find_element(By.ID, field_id)
field.clear()
field.send_keys(string)

Expand All @@ -475,7 +477,7 @@ def put_into_field(field_id, string):
fathom_fox_uuid = get_fathom_fox_uuid(firefox)
firefox.get(f'moz-extension://{fathom_fox_uuid}/pages/vector.html')

ruleset_dropdown_selector = Select(firefox.find_element_by_id('trainee'))
ruleset_dropdown_selector = Select(firefox.find_element(By.ID, 'trainee'))
try:
ruleset_dropdown_selector.select_by_visible_text(trainee_id)
except NoSuchElementException:
Expand All @@ -487,8 +489,8 @@ def put_into_field(field_id, string):
put_into_field('maxTabs', str(tabs))

number_of_samples = len(sample_filenames)
status_box = firefox.find_element_by_id('status')
vectorize_button = firefox.find_element_by_id('freeze')
status_box = firefox.find_element(By.ID, 'status')
vectorize_button = firefox.find_element(By.ID, 'freeze')
completed_samples = 0
print('done.')

Expand All @@ -511,7 +513,7 @@ def put_into_field(field_id, string):
completed_samples = now_completed_samples
sleep(.25)

download_dir = Path(firefox.profile.default_preferences['browser.download.dir'])
download_dir = Path(firefox.options.preferences['browser.download.dir'])
new_file = wait_for_vectors_in(download_dir)
unlink_if_exists(output_path) # move() won't overwrite a file on Windows.
output_path.parent.mkdir(parents=True, exist_ok=True)
Expand Down
2 changes: 1 addition & 1 deletion cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'numpy>=1.18.1,<1.24.0',
'filelock>=3.0.12',
'scikit-learn>=0.22.2',
'selenium>=3.141.0',
'selenium>=4.10.0,<5.0',
'tensorboardX>=1.6,<2.0',
'torch>=1.0,<2.0',
'protobuf <= 3.20.1',
Expand Down

0 comments on commit d126115

Please sign in to comment.