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.
  • Loading branch information
linabutler committed Jun 28, 2023
1 parent 70f902e commit 9c6b037
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
39 changes: 22 additions & 17 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,27 @@ 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)
options = webdriver.FirefoxOptions()

firefox = webdriver.Firefox(
if not show_browser:
options.add_argument('-headless')

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 +471,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 +480,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 +492,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 +516,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 9c6b037

Please sign in to comment.