I'm creating a small program that logins to my Memrise (a vocabulary-learning app) account, opens tabs on each course, check if I have any remaining vocabulary to review, and if there are, start the session and if not, close the tab.
So far, I made success with the app, but now found that the browser I launched via Selenium is extremely slow once I navigate and tap the word on my own. For example, it takes about 5 second for my typing to be reflected on the screen, which is not true if I type on normal Google Chrome. It is slow even after my program finishes the execution (but the driver is still there to let me review the words). I wonder what makes it too slow and would like to know if there is any way to make it as smooth as when I navigate it on my ordinary Chrome browser.
I'm not sure if I can show anything helpful, as everything I wrote is too simple a structure. First create a Selenium driver:
options = webdriver.ChromeOptions()
prefs = {
"download.default_directory" : download_dir,
'intl.accept_languages': 'en,en_US'
}
options.add_experimental_option("prefs", prefs)
options.add_experimental_option("detach", True)
options.add_experimental_option("useAutomationExtension", False)
options.add_experimental_option("excludeSwitches", ["enable-automation"])
driver = webdriver.Chrome(options=options)
driver.maximize_window()
Then for all the URLs in a list, call driver.execute_script('window.open("{0}", "_blank");'.format(url)) to open it in a new tab.
Then, just tab the Review button if there is a review, and close the window if not.
remaining_window_handles = driver.window_handles
window_count = len(driver.window_handles)
while window_count > 0:
driver.switch_to_window(remaining_window_handles[0])
driver.execute_script("scroll(0, 0);")
try:
review_button = WebDriverWait(driver, 6).until(
expected_conditions.presence_of_element_located((By.XPATH, '//a[@data-original-title="Review words you\'ve learned"]'))
)
try: # a course with review has the number of reviews in its text
numbers = re.findall(r'\d+', review_button.text)
if numbers:
review_button.click()
else:
driver.close()
except (NoSuchElementException, NoSuchWindowException):
driver.close()
except TimeoutException:
driver.close()
window_count -= 1
I execute it by first launching IPython session, and then run the script. I wonder if the problem comes from the fact that I run it on iTerm2 (M1 MacBook Air), and on Activity Monitor, it seems that normal Chrome is running with Apple type yet the Selenium one is with Intel.