I'm trying to run the test code that has been shared in Selenium documentation, because I use WSL2, I'm running Firefox webdriver in headless mode;
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
#driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
There is no error outputs on command line. However, the geckofile.log file outputs like this,
1602532495397 geckodriver INFO Listening on 127.0.0.1:52679
1602532495400 mozrunner::runner INFO Running command: "/usr/bin/firefox" "--marionette" "-headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofiletLwjrV"
*** You are running in headless mode.
console.error: SearchCache: "_readCacheFile: Error reading cache file:" (new Error("", "(unknown module)"))
1602532496837 Marionette INFO Listening on port 38037
1602532496906 Marionette WARN TLS certificate errors will be ignored for this session
JavaScript error: resource://gre/actors/AutoCompleteChild.jsm, line 235: Error: Invalid autocomplete selectedIndex
1602532499412 Marionette INFO Stopped listening on port 38037
1602534735902 geckodriver INFO Listening on 127.0.0.1:42551
1602534735905 mozrunner::runner INFO Running command: "/usr/bin/firefox" "--marionette" "-headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofilecTeoz7"
*** You are running in headless mode.
console.error: SearchCache: "_readCacheFile: Error reading cache file:" (new Error("", "(unknown module)"))
1602534737300 Marionette INFO Listening on port 38781
1602534737312 Marionette WARN TLS certificate errors will be ignored for this session
1602534739717 Marionette INFO Stopped listening on port 38781
How can I fix this problem and do Web Scraping under WSL2?