So I'm working with Selenium IDE and it beautifully generated the code for me. But I have an issue with webdriver. This is the code.
package org.example;// Generated by Selenium IDE
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.JavascriptExecutor;
import java.util.*;
public class StorwareTestTest {
WebDriver driver;
Map<String, Object> vars;
JavascriptExecutor js;
@Before
public void setUp () {
driver = new ChromeDriver();
js = (JavascriptExecutor) driver;
vars = new HashMap<String, Object>();
}
@After
public void tearDown () {
driver.quit();
}
@Test
public void storware () {
System.setProperty("webdriver.chrome.driver", "C:/Users/wrost/Downloads/chromedriver_win32/chromedriver.exe");
driver.get("https://storware.eu/");
(...)
So, the compiler is yelling at me that: The path to the driver executable must be set by the webdriver.chrome.driver system property; But I did it. Maybe in the wrong place. What can I do to fix it? I've been working on it for 2 hours, and honestly have no idea. Maybe it's some basic problem. I'm a fresher. And the code is autogenerated by SeleniumIDE, so it probably does a bunch of stuff I don't even know about. Maybe it shouldn't be under @Test annotation. But then where? (When I was writing basic programs using Selenium with Java everything worked. But I also want to know how SeleniumIDE works, and that's where the problems started). Thanks for Your help!
CodePudding user response:
Ideally the System.setProperty()
line should be mentioned before you initialize the ChromeDriver driven google-chrome browsing context.
Effectively your code block will be:
@Before
public void setUp () {
System.setProperty("webdriver.chrome.driver", "C:/Users/wrost/Downloads/chromedriver_win32/chromedriver.exe");
driver = new ChromeDriver();
js = (JavascriptExecutor) driver;
vars = new HashMap<String, Object>();
}