简体   繁体   中英

Eclipse Error when trying to run in windows

Exception in thread "main" java.lang.IllegalStateException: The driver executable must exist: C:\chromedriver.exe
    at org.openqa.selenium.internal.Require$FileStateChecker.isFile(Require.java:315)
    at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:144)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:139)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:38)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:231)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:434)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:127)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:46)
    at base.main(base.java:35)

Hi Guys was trying to do some practice but always this error comes up it will be really helpful if you guys can help me to understand the error. I tried setting up the selenium driver path but still error not going away. the code is on the bottom.Thank you in advance

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class base {
    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub
        System.setProperty("webdriver.chrome.driver", "C://chromedriver.exe");
        WebDriver driver=new ChromeDriver();
        //driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        WebDriverWait w =new WebDriverWait(driver,5);
        String[] itemsNeeded= {"Cucumber","Brocolli","Beetroot"};
        driver.get("https://rahulshettyacademy.com/seleniumPractise/");
        Thread.sleep(3000);
        addItems(driver,itemsNeeded);
        driver.findElement(By.cssSelector("img[alt='Cart']")).click();
        driver.findElement(By.xpath("//button[contains(text(),'PROCEED TO CHECKOUT')]")).click();
        w.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input.promoCode")));
        driver.findElement(By.cssSelector("input.promoCode")).sendKeys("rahulshettyacademy");
        driver.findElement(By.cssSelector("button.promoBtn")).click();
        //explicit wait
        w.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("span.promoInfo")));
        System.out.println(driver.findElement(By.cssSelector("span.promoInfo")).getText());
    }
    
    public static  void addItems(WebDriver driver,String[] itemsNeeded)
    {
        int j=0;
        List<WebElement> products=driver.findElements(By.cssSelector("h4.product-name"));
        for(int i=0;i<products.size();i++)
        {
            //Brocolli - 1 Kg
            //Brocolli,    1 kg
            String[] name=products.get(i).getText().split("-");
            String formattedName=name[0].trim();
            //format it to get actual vegetable name
            //convert array into array list for easy search
            //  check whether name you extracted is present in arrayList or not-
            List itemsNeededList = Arrays.asList(itemsNeeded);
            if(itemsNeededList.contains(formattedName))
            {
                j++;
                //click on Add to cart
                driver.findElements(By.xpath("//div[@class='product-action']/button")).get(i).click();
                if(j==itemsNeeded.length)
                {
                    break;
                }
            }
        }
    }
}
 System.setProperty("webdriver.chrome.driver", "C://chromedriver.exe");

defines that the chrome driver binary is located at C:\chromedriver.exe . But the exception says the file does not exists there.

So just download the chrome driver from https://chromedriver.chromium.org/downloads and move + rename it to C:\chromedriver.exe and it will work.

This error message...

Exception in thread "main" java.lang.IllegalStateException: The driver executable must exist: C:\chromedriver.exe

...implies that the program was unable to find the ChromeDriver executable in the specified location.


Solution

You need to take care of a couple of things here as follows:

  • Ensure that you have downloaded the exact format of the ChromeDriver binary from the download location pertaining to your underlying OS among:

    • chromedriver_win32 : For Windows OS
    • chromedriver_mac64 : For MAC OS X
    • chromedriver_linux64 : For Linux OS
  • Instead of storing the ChromeDriver executable within C:\ drive, keep it within a directory , eg C:\BrowserDrivers\ . So effectively your line of code will be:

     System.setProperty("webdriver.chrome.driver", "C://BrowserDrivers//chromedriver.exe");
  • Ensure that ChromeDriver binary have executable permission for the non-administrator user.

  • Execute your Test as a non-administrator user.

[1642448880.155][SEVERE]: Unable to receive message from renderer Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created from disconnected: Unable to receive message from renderer (Session info: chrome=97.0.4692.71) Build info: version: '4.0.0', revision: '3a21814679' System info: host: 'LENOVO', ip: '192.168.227.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.2' Driver info: org.openqa.selenium.chrome.ChromeDriver Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}}}] at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.Z93F725A07423FE1C8 89F448B33D21F46Z:84) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:62) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156) at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:164) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:139) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:559) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:246) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.Z93F72 5A07423FE1C889F448B33D21F46Z:168) at org.openqa.selenium.chromium.ChromiumDriver.(ChromiumDriver.java:108) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:104) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:91) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:46) at base.main(base.java:16)

I AM STILL GETTING THIS ERROR EVEN AFTER DOWNLOADING CHROMEDRIVER

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM