2

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

2

2 Answers 2

2

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>

Reload the project to update the dependencies.

proof of work

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

Sign up to request clarification or add additional context in comments.

9 Comments

Thank You CrazyCoder. Unfortunately, after adding this dependency, it still doesn't work for me.
I added all dependencies You've suggested, reloaded the project, Invalidated and restarted and it still doesn't work.
Try removing the test scope from pom.xml if your code is not inside the test source roots.
OK. Thank You. Your last suggestion helped me to fix the problem. I copied the whole code into a different folder in the project. Instead of creating the class in src>test>java I created one in src>main>java. And now everything works. But hell, I have no idea why. Thank You so much.
|
-1
  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 😉

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.