確定了瀏覽器版本和chromedriver版本可以對應得上,但是每次調用對應的服務都會報該錯誤
問題在于啟動Selenium需要桌面,然而你的Linux上沒有桌面,所以報錯,解決這個問題的方式是將Selenium設置為不使用瀏覽器啟動,然而不使用瀏覽器啟動存在對應的元素沒加載的問題,解決該問題的方式是設置瀏覽器大小,我的是1366-768,使用了這個配置之后問題就解決了文章來源:http://www.zghlxwxcb.cn/news/detail-772124.html
配置代碼如下文章來源地址http://www.zghlxwxcb.cn/news/detail-772124.html
public class ChromeUtil {
public static ChromeDriver getChromeDriver() {
// 本地測試,本地需配置同版本的chromedriver和Chrome,測試時保持Chrome網(wǎng)頁運行
// chrome會自動更新,需注意保持版本不變
// 快速入門教學:https://blog.csdn.net/chenjxj123/article/details/121802904
System.setProperty("webdriver.chrome.driver", "/usr/local/chromeDriver/chromedriver");
ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*");
options.addArguments("--headless");
ChromeDriver driver = new ChromeDriver(options);
driver.manage().window().setSize(new Dimension(1366,768));
return driver;
}
}
到了這里,關于Linux調用Selenium報session not created: Chrome failed to start: exited normally.的問題解決方式的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!