0

My distro doesn't provide a 'selenium' package

$ apt search selenium p libtest-www-selenium-perl - Perl test framework using Selenium Remote Control i A python3-selenium - Python3 bindings for Selenium p qunit-selenium - Run QUnit tests through Selenium WebDriver p ruby-selenium-webdriver.

I've tried this and this approaches and the browser does get invoked successfully. This is my code.


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
//import selenium.webdriver;
//import selenium.webdriver.support.ui.WebDriverWait;
//import selenium.webdriver.common.by.By;
//import selenium.webdriver.support.expected_conditions;


import static org.openqa.selenium.By.*;
//import static sun.security.util.KnownOIDs.EC;

public class Login {
    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.gecko.driver", "./geckodriver");
        WebDriver dr = new FirefoxDriver();
        dr.get("https://google.com/");
        dr.manage().window().maximize();
        //Click on "Join now"
        WebElement join = dr.findElement(xpath("//a[@class='newUser green']"));
        //WebDriverWait(driver, 20).until(EC.element_to_be_clickable((xpath("//a[@class='newUser green']")))).click();
        join.click();

    }
}

My problem is uncommenting any of the imports breaks because java has no idea what a selenium is. How do I add it? Linux Mint.

  • You have to add the related jars to th class path.Selenium for other languages will not help you https://mvnrepository.com/artifact/org.seleniumhq.selenium – Jens Feb 20 '23 at 07:59
  • Use maven to manage your dependencies. – tgdavies Feb 20 '23 at 08:13

3 Answers3

1

Welcome. There is a lot going on in your quesrion: intelij; Java class paths; import statements.

I recommend tackling it one at a time.

  1. copy the java example on selenium.dev doco page.

  2. Run commandline javac.exe directly javac command examples (code Java.net) look for the 'Compile a source file which depends on multiple libraries' example. NOTE: the import statements are class references... Don't use the filename (is different to python).

  3. Search Web for how to configure classpath for intelij.

dank8
  • 361
  • 4
  • 20
0
  1. Go to https://chromedriver.chromium.org/downloads page
  2. Depends on your Chrome version, Download Linux chrome driver zip package
  3. Unip package and locate under any folder that is in system PATH or add your folder to PATH
  4. Go to https://www.selenium.dev/downloads/ and download Selenium Java package and locate it under your project's library package(depends on your project/IDE settings)
Mahsum Akbas
  • 1,523
  • 3
  • 21
  • 38
0

This is certainly the wrong answer especially as You are using an IDE but at least it works - for me.


java works with .class files. So:

  1. Download Selenium.
  2. Unzip selenium-api.jar.
  3. Either
    • place the unzipped content in the source code directory OR
    • set the environment variable CLASSPATH OR
    • invoke javac with -classpath switch.

The imports will be discovered.

Vorac
  • 8,726
  • 11
  • 58
  • 101