versionNumber
这是我的代码。我正在尝试使用webdriver创建Firefox实例。 我收到以下错误。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
def set_pref(path):
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.dir", path)
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk",
"application/csv,application/excel,application/vnd.msexcel,application/vnd.ms-excel,text/anytext,text/comma-separated-values,text/csv,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/octet-stream")
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.helperApps.neverAsk.openFile",
"application/csv,application/excel,application/vnd.msexcel,application/vnd.ms-excel,text/anytext,text/comma-separated-values,text/csv,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/octet-stream")
profile.set_preference("browser.helperApps.alwaysAsk.force", False)
profile.set_preference("browser.download.manager.useWindow", False)
profile.set_preference("browser.download.manager.focusWhenStarting", False)
profile.set_preference("browser.download.manager.alertOnEXEOpen", False)
profile.set_preference("browser.download.manager.showAlertOnComplete", False)
profile.set_preference("browser.download.manager.closeWhenDone", True)
profile.set_preference("pdfjs.disabled", True)
return webdriver.Firefox(firefox_profile=profile)
def main():
display = Display(visible=1, size=(1050, 800))
display.start()
driver = set_pref(path)
if __name__ == "__main__":
main()
firefox版本63.0 | 硒版本3.14.1 | geckodriver版本0.18.0
自早上以来,我无法运行任何脚本。无法找出问题出在哪里。
答案 0 :(得分:2)
根据此兼容性图表https://firefox-source-docs.mozilla.org/testing/geckodriver/geckodriver/Support.html,您的geckodriver不支持Firefox> 62。因此答案可能很简单:更新您的geckodriver。
答案 1 :(得分:1)
要始终确认geckodriver与您当前的firefox和selenium版本兼容,请执行以下操作:
如果您使用的是Windows OS,请在System32上保留下载的geckodriver;如果您使用的是Mac OSX,请保持在/ usr / local / bin下。从here
下载java -jar selenium-server-standalone-3.14.0.jar