Python 在WSL2下使用selenium时出现控制台错误
我正在尝试运行Selenium文档中共享的测试代码,因为我使用WSL2,我在headless模式下运行FirefoxWebDriverPython 在WSL2下使用selenium时出现控制台错误,python,selenium,selenium-webdriver,firefox,windows-subsystem-for-linux,Python,Selenium,Selenium Webdriver,Firefox,Windows Subsystem For Linux,我正在尝试运行Selenium文档中共享的测试代码,因为我使用WSL2,我在headless模式下运行FirefoxWebDriver from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.firefox.options import Options options = Options() options.headless = True d
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()
命令行上没有错误输出。但是,geckofile.log文件输出如下:
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
如何解决此问题并在WSL2下进行Web抓取