How to set Google Chrome in WebDriver

前端 未结 6 1914
庸人自扰
庸人自扰 2020-12-10 11:43

I am trying to set Chrome as my browser for testing with Web-Driver and set the chromedriver.exe file properly but I am still getting the following error:

or         


        
相关标签:
6条回答
  • 2020-12-10 11:58

    Mac OS: You have to install ChromeDriver first:

    brew cask install chromedriver

    It will be copied to /usr/local/bin/chromedriver. Then you can use it in java code classes.

    0 讨论(0)
  • 2020-12-10 11:59

    I'm using this since the begin and it always work. =)

    System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("http://www.google.com");
    
    0 讨论(0)
  • 2020-12-10 12:00

    Aditya,

    As you said in your last comment that you are trying to access chrome of some other system so based on that you should keep your chrome driver in that system itself.

    for example: if you are trying to access linux chrome from windows then you need to put your chrome driver in linux at some place and give permission as 777 and use below code at your windows system.

    System.setProperty("webdriver.chrome.driver", "\\var\\www\\Jar\\chromedriver");
    Capability= DesiredCapabilities.chrome();   Capability.setPlatform(org.openqa.selenium.Platform.ANY);
    browser=new RemoteWebDriver(new URL(nodeURL),Capability);
    

    This is working code of my system.

    0 讨论(0)
  • 2020-12-10 12:10

    It was giving Illegal Exception.

    My workaround with code:

    public void dofirst(){
        System.setProperty("webdriver.chrome.driver","D:\\Softwares\\selenium\\chromedriver_win32\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("http://www.facebook.com");
    }
    
    0 讨论(0)
  • 2020-12-10 12:15

    For Mac -Chrome browser

    public class MultipleBrowser {
    
        public WebDriver driver= null;
        String browser="mozilla";
        String url="https://www.omnicard.com";
    
        @BeforeMethod
        public void LaunchBrowser() {
    
          if(browser.equalsIgnoreCase("mozilla"))
              driver= new FirefoxDriver();
          else if(browser.equalsIgnoreCase("safari"))
              driver= new SafariDriver();
          else if(browser.equalsIgnoreCase("chrome"))
              System.setProperty("webdriver.chrome.driver","/Users/mhossain/Desktop/chromedriver");
              driver= new ChromeDriver();   
              driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
              driver.navigate().to(url);
              //driver.manage().deleteAllCookies();
    
      }
    
    0 讨论(0)
  • 2020-12-10 12:21
    public void setUp() throws Exception {
    
     System.setProperty("webdriver.chrome.driver","Absolute path of Chrome driver");
    
     driver =new ChromeDriver();
     baseUrl = "URL/";
    
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      }
    
    0 讨论(0)
提交回复
热议问题