This error message...
org.openqa.selenium.remote.NoSuchDriverException: geckodriver located at geckodriver.exe, but invalid
...implies that Selenium was unable to locate the required GeckoDriver in the path mentioned by the key webdriver.gecko.driver
through the System.setProperty()
line, as the expectation is the key webdriver.gecko.driver
would contain the full path to the GeckoDriver binary as follows:
System.setProperty("webdriver.gecko.driver", "C:\\full\\path\\to\\geckodriver.exe");
Using Selenium Manager
As you are using Selenium v4.11.0 you can remove the following line of code:
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
as Selenium Manager which is now fully integrated with Selenium will download the matching GeckoDriver silently in the background and execute the test.
Your effective code block will be:
WebDriver driver = new FirefoxDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.get("https://www.google.com/");