So I'm learning Selenium for test automation with Java, and I have an error message like in the title, "window()" in IntelliJ is red .
I was trying to import org.openqa.selenium.WebDriver.Options, but its grayed out, so useless.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebDriver.Options; //this one is grayed out
public class WindowsActivities {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "resources/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
}
}
What can I do to fix this?
Thanks in advance
CodePudding user response:
It looks like you are missing this dependency (which also provides selenium-api
):
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.2.1</version>
</dependency>
Make sure you also have this dependency:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>4.2.1</version>
</dependency>
Please also try File | Invalidate Caches | Invalidate and Restart.
CodePudding user response:
I recommend you to use
WebDriverManager
, that carries out the management of the drivers required by Selenium WebDriver: https://github.com/bonigarcia/webdrivermanagerAlso I recommend you to use
Selenide
, build on Selenium, which has a lot more advantages, instead of pure Selenium: https://selenide.org/
It will make your work easier and faster