Using Selenium on Mac Chrome

前端 未结 5 861
说谎
说谎 2020-12-13 03:15

Recently got a mac and was able to run Mozilla without any issues but having trouble installing chrome extensions and running it for selenium. Can someone guide me through t

相关标签:
5条回答
  • 2020-12-13 03:25

    Step 1: Download chromedriver

    # You can find more recent/old versions at http://chromedriver.storage.googleapis.com/
    wget http://chromedriver.storage.googleapis.com/81.0.4044.69/chromedriver_mac64.zip
    

    Step 2: Add chromedriver to /usr/local/bin

    unzip chromedriver_mac64.zip
    cp chromedriver /usr/local/bin
    

    You should now be able to run

    from selenium import webdriver
    
    browser = webdriver.Chrome()
    browser.get('http://localhost:8000')
    

    without any issues

    0 讨论(0)
  • 2020-12-13 03:43

    I think that the easy way for running mac osx, chrome and selenium together is like this on mac os terminal:

    # download selenium jar
    curl -L0 https://selenium-release.storage.googleapis.com/3.9/selenium-server-standalone-3.9.1.jar -o selenium-server-standalone.jar
    
    # install chromedriver using cask
    brew cask install chromedriver
    
    # start chrome driver
    brew services start chromedriver                                                                                                                                                                      
    #==> Successfully started `chromedriver` (label:homebrew.mxcl.chromedriver)
    
    # start selenium server
    java -jar selenium-server-standalone.jar                                                                                                                                                                           
    #14:38:20.684 INFO - Selenium build info: version: '3.9.1', revision: '63f7b50'
    #14:38:20.685 INFO - Launching a standalone Selenium Server on port 4444
    
    0 讨论(0)
  • 2020-12-13 03:45

    If you want to use Selenium WebDriver with Chrome, first download ChromeDriver - WebDriver for Chrome. This can be installed via Homebrew with brew install chromedriver, or manually by downloading, extracting, moving and setting the PATH as follows:

    $ cd $HOME/Downloads
    $ wget http://chromedriver.storage.googleapis.com/2.22/chromedriver_mac32.zip
    $ unzip chromedriver_mac32.zip
    $ mkdir -p $HOME/bin
    $ mv chromedriver $HOME/bin
    $ echo "export PATH=$PATH:$HOME/bin" >> $HOME/.bash_profile
    

    Source: install and set path to chromedriver on mac or linux

    You should then read Getting started with ChromeDriver on Desktop, in particular the sample code which shows how you map the path to the executable and instantiate ChromeDriver. If you have a reference to the driver in the PATH variable, you can omit the configuration line.

    You can install both packed (.crx file) and unpacked (directory) extensions via ChromeDriver. See the code snippets for setting either up here.

    If you were using Selenium IDE for FireFox instead, there is no version available for Chrome. The best alternative I know of is iMacros for Chrome.

    0 讨论(0)
  • 2020-12-13 03:45
    1. One way is if you have homebrew on your mac, then on terminal, use this command brew install chromedriver
    2. Then you need to download chromedriver on your machine, do it from http://chromedriver.storage.googleapis.com/index.html Download latest version It will look like, "chromedriver_mac32.zip" (doesn't matter if its 32 bit, it will work for 64 bit MAC as well)
    3. Use this code for open Chrome if your chromedriver that you downloaded is inside your project folder and looks like this ..Project folder/Chrome/chromedriver

       System.setProperty("webdriver.chrome.driver", 
       System.getProperty("user.dir")+"/Chrome/chromedriver");
       driver=new ChromeDriver();
      
    0 讨论(0)
  • 2020-12-13 03:46

    Sometimes you will face a problem with the old version of chromedriver and when you try to install it using this command:

    brew cask install chromedriver
    

    It shows you the following:

    Error: It seems there is already a Binary at '/usr/local/bin/chromedriver'; not linking.
    

    However, you can the following step:

    brew cask reinstall chromedriver
    

    If it still shows you the same error, you can remove it with the following command

    rm /usr/local/bin/chromedriver
    

    and install it again

    brew cask install chromedriver
    

    You should have the last updated version of chrome driver

    0 讨论(0)
提交回复
热议问题