Home > database >  "Cannot find method window()" in IntelliJ (Java)
"Cannot find method window()" in IntelliJ (Java)

Time:07-27

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>

proof of work

Please also try File | Invalidate Caches | Invalidate and Restart.

CodePudding user response:

  1. I recommend you to use WebDriverManager, that carries out the management of the drivers required by Selenium WebDriver: https://github.com/bonigarcia/webdrivermanager

  2. Also 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

  • Related