Как указать бинарный файл браузера в Selenium WebDriver Java? Или как решить ошибку, описанную ниже?
Selenium-java 4.7.2
Java 19.0.1
при выполнении кода
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\Username\\IdeaProjects\\project\\drivers\\geckodriver.exe");
FirefoxDriver driver = new FirefoxDriver();
driver.get("https://google.com");
появляется ошибка
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
Насколько я понял, FireFox у меня установлен не в стандартный каталог, поэтому нужно вручную указать путь к firefox.exe. Как это сделать? Пробовал
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\username\\IdeaProjects\\project\\drivers\\geckodriver.exe");
FirefoxBinary binpath = new FirefoxBinary(new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe"));
FirefoxDriver driver = new FirefoxDriver();
driver.get("https://google.com");
}
Та же самая ошибка, полный текст ошибки:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 1672419301824 geckodriver INFO Listening on 127.0.0.1:14274 Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line Host info: host: 'DESKTOP-3NVOT8O', ip: '192.168.100.7' Build info: version: '4.7.2', revision: '4d4020c3b7' System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '19.0.1' Driver info: org.openqa.selenium.firefox.FirefoxDriver Command: [null, newSession {capabilities=[Capabilities {acceptInsecureCerts: true, browserName: firefox, moz:debuggerAddress: true, moz:firefoxOptions: {}}], desiredCapabilities=Capabilities {acceptInsecureCerts: true, browserName: firefox, moz:debuggerAddress: true, moz:firefoxOptions: {}}}] at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:148) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:106) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156) at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:535) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:228) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:156) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:130) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:111) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:101) at Main.main(Main.java:14)
Process finished with exit code 1