添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am new to Automation and trying to learn Automation as a manual tester. I am trying to execute a simple java code to open a Chrome browser using Selenium Webdrivers and get the below exception. Tried all possible ways to resolve the same and still nothing works. Any help would really help. Thanks.

Starting ChromeDriver 2.28.455520 (cc17746adff54984afff480136733114c6b3704b) on port 3527
Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 4.67 seconds
Build info: version: '2.51.0', revision: '1af067d', time: '2016-02-05 19:11:55'
System info: host: 'BTP196816', ip: '10.241.51.20', os.name: 'Windows 8.1', os.arch: 'x86', os.version: '6.3', java.version: '1.7.0_99'
Driver info: org.openqa.selenium.chrome.ChromeDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:170)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:159)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116)
    at OpenAdf.LaunchAdf.main(LaunchAdf.java:11)
                Some additional information on the versions being used: Chrome Version: 55; Java version: jre 1.7.0_99; Selenium Java version: 2.51; selenium server standlaone 2.51; Chromedriver version: 2.28
– Sowmya Dhandapani
                Oct 29, 2018 at 12:37
                the error said it's not found the chrome binary. You need to give the path of your chrome driver. String exepath="/home/user/mars workspace/SeleniumTest/chromedriver"; 		 System.setProperty("webdriver.chrome.driver", exepath);
– Hiten
                Oct 29, 2018 at 12:37
                Instead of providing a string, I have given the same as an argument in the setproperty. But still Ihave tried as you have mentioned but still getting the same error.
– Sowmya Dhandapani
                Oct 29, 2018 at 12:41
                share your code here, what you tried. If you are using chrome driver of 2.28 version then your chrome browser must be 57+ version. Check here sites.google.com/a/chromium.org/chromedriver/downloads
– Hiten
                Oct 29, 2018 at 12:42
                Hi Hiten, Here is my code that Im trying package OpenAdf;  import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver;  public class LaunchAdf {  	public static void main(String[] args) throws Exception { 		 		System.setProperty("webdriver.chrome.driver", "C:\\SeleniumDrivers\\chromedriver_win32\\chromedriver.exe"); 		WebDriver driver = new ChromeDriver(); 		driver.get("google.com/");  	}  }
– Sowmya Dhandapani
                Oct 29, 2018 at 13:12

try using that :

        System.setProperty("webdriver.chrome.driver", "C:\\SeleniumDrivers\\chromedriver_win32\\chromedriver.exe");
        DesiredCapabilities capability = new DesiredCapabilities();
        capability.setCapability("binary", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
        WebDriver driver = new ChromeDriver(capability);

You can also try

capability.setCapability("chrome.binary", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");

Hope it helps.

Thanks a ton Hiten.. It worked. From your above code I understood that Selenium is looking for the Chrome browser in the location: "C:\Program Files (x86)\Google\Chrome\Application" and in my machine the location of Chrome was different. I just manually moved Chrome to the exact location and used my same code and it worked. Thank you so much. This is of so much help. I was struggling with this simple piece since 2 days. – Sowmya Dhandapani Oct 29, 2018 at 14:12
System.setProperty("webdriver.chrome.driver", "C:\\SeleniumDrivers\\chromedriver_win32\\chromedriver.exe");

Need to set the chrome driver path and the chrome driver path must be at the location which you gave in the code.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.