Reputation: 51
I'm using JDK 1.15.0.1 and Java version 8. In conjunction with the Selenium library from here I've also been using the Chrome driver from here
I've tried all the tutorials I could find on the web and can't figure out how to install the latest Selenium WebDriver library successfully. I've primarily followed this tutorial (and ones similar to it) as closely as possible with slight variation for each attempt after the first to no avail. Eclipse keeps indicating that my program isn't registering the library or importing the packages within correctly by stating the it "cannot find symbol [class from selenium library]" upon hovering over the associated class usages in the test code.
I've tried a similar approach and similar tutorials with the same files in the Netbeans IDE with the same result.
Here's the test code I've been using:
package internet.bot;
/**
*
* @author Owner
*/
public class InternetBot {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//for the web driver
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Owner\\Documents\\GitHub\\Internet-Bot\\Internet Bot\\src\\chromedriver_win32\\chromedriver_win32\\chromedriver.exe");
// Create a new instance of the html unit driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new ChromeDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
}
}
/*Sources
Example Google Search code: https://stackoverflow.com/questions/4640972/how-to-have-java-application-interact-with-a-website
*/
Edit: I think I should also mention that the selenium library I downloaded doesn't have as many .jar files as the one shown in the tutorial referenced.
Upvotes: 1
Views: 2372
Reputation: 7563
I'm trying to suggest configure your project with Maven, this is easier.
After you have created a project, right click on it.
Select Configure > Convert to Maven Project > Finish
It will automatically generate the pom.xml
file.
Note : Here, make sure you are connected to the internet.
After that, please add the selenium dependency according to the version you want between the closing </build>
and closing </project>
like bellow:
pom.xml
....
....
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
</project>
Save and the project will build automatically, and wait a few moments for the workspace to finish configuring.
Upvotes: 1
Reputation: 26
I think if you can go for a Mavan project, its better when upgrading/downgrading the versions and the plugings
Upvotes: 0