Wednesday, March 1, 2023

Step-by-step guide to install and set up Selenium with IntelliJ

Here's a step-by-step guide to install and set up Selenium with IntelliJ:
  1. Download and install IntelliJ IDEA Community Edition from https://www.jetbrains.com/idea/download/

  2. Open IntelliJ IDEA and create a new project.

  3. Click on File > Project Structure.

  4. In the Project Structure dialog box, click on Libraries.

  5. Click on the "+" sign to add a new library.

  6. Select "From Maven" and search for "Selenium".

  7. Select "org.seleniumhq.selenium:selenium-java" and click on "OK".

  8. Wait for IntelliJ to download and add the Selenium library to your project.

  9. Create a new Java class and name it "TestSelenium".

  10. Copy and paste the following code into the TestSelenium.java 

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class TestSelenium {
    public static void main(String[] args) {
        // Set the path to the Chrome driver
        System.setProperty("webdriver.chrome.driver", "C:/chromedriver.exe");

        // Create a new instance of the Chrome driver
        WebDriver driver = new ChromeDriver();

        // Navigate to Google
        driver.get("http://www.google.com");

        // Close the browser
        driver.quit();
    }
}

  1. Replace "C:/chromedriver.exe" with the path to the Chrome driver on your computer.

  2. Save the TestSelenium.java file.

  3. Right-click on the TestSelenium.java file and click on "Run 'TestSelenium.main()'".

  4. Wait for the Chrome browser to open and navigate to Google.

  5. Verify that the browser opens and navigates to Google successfully.

That's all! You have successfully installed and set up Selenium with IntelliJ.