My IDE is eclipse and I'm using Selenium Webdriver on MAC. Every time I execute my code below, I want to kill/close the previously opened browser and then start a new instance and leave it on. As a result, only one instance of browser should be open at a time. I am not doing this for testing purpose. I'm just doing this because I want to automate a task.
This is the error I am getting everytime I execute my code:
Cannot run program "START": error=2, No such file or directory
This is my code:
public class Demo {
public static void main(String[] args){
System.setProperty("webdriver.chrome.driver", "/Users/Downloads/chromedriver/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");
try{
Runtime.getRuntime().exec("START taskkill /F /IM chrome.exe");
System.exit(0);
}
catch(IOException io){
System.out.println(io.getMessage());
}
}
}
This is working fine on windows. How do I fix this on MAC/unix/ environment or what changes should I make in my code?
I was told this error is something to do with admin privileges so I should run eclipse as an admin. So I did this: sudo open Eclipse.app/
. So the eclipse opened as admin and executed the code but I was still getting the same error.