diff --git a/cli/fathom_web/vectorizer.py b/cli/fathom_web/vectorizer.py index 0137a103..c8dc038e 100644 --- a/cli/fathom_web/vectorizer.py +++ b/cli/fathom_web/vectorizer.py @@ -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 @@ -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) @@ -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) @@ -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: @@ -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.') @@ -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) diff --git a/cli/setup.py b/cli/setup.py index 87e3148b..f95a0d72 100644 --- a/cli/setup.py +++ b/cli/setup.py @@ -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',