오류 메시지 : " 'chromedriver'실행 파일이 경로에 있어야합니다"
나는 파이썬과 함께 셀레늄을 사용하고 있으며이 사이트에서 내 Windows 컴퓨터 용 chromedriver를 다운로드했습니다 : http://chromedriver.storage.googleapis.com/index.html?path=2.15/
zip 파일을 다운로드 한 후 zip 파일의 다운로드 폴더로 압축을 풉니 다. 그런 다음 실행 가능한 바이너리 (C : \ Users \ michael \ Downloads \ chromedriver_win32)의 경로를 환경 변수 "경로"에 넣습니다.
그러나 다음 코드를 실행할 때 :
from selenium import webdriver
driver = webdriver.Chrome()
... 다음과 같은 오류 메시지가 계속 나타납니다.
WebDriverException: Message: 'chromedriver' executable needs to be available in the path. Please look at http://docs.seleniumhq.org/download/#thirdPartyDrivers and read up at http://code.google.com/p/selenium/wiki/ChromeDriver
그러나-위에서 설명한 것처럼 실행 파일은 경로에 있습니다 ...! 여기서 무슨 일이 일어나고 있습니까?
cmd를 열고 chromedriver
chromedriver 실행 파일의 이름이 여전히 다음과 같다고 가정하면 Enter 키를 누르면 실제로 PATH에 있는지 테스트 할 수 있습니다 . 경우 Starting ChromeDriver 2.15.322448
나타나는되면, PATH가 적절하게 설정하고 잘못가는 뭔가가있다.
또는 다음과 같이 chromedriver의 직접 경로를 사용할 수 있습니다.
driver = webdriver.Chrome('/path/to/chromedriver')
따라서 특정 경우 :
driver = webdriver.Chrome("C:/Users/michael/Downloads/chromedriver_win32/chromedriver.exe")
바이너리를 다운로드하고 경로를 수동으로 구성하여 chromedriver를 설정하는 기존 방법에 대한 토론이 여전히 진행되고 있음을 알 수 있습니다.
이것은 웹 드라이버 관리자를 사용하여 자동으로 수행 할 수 있습니다
pip install webdriver-manager
이제 질문의 위 코드는 아래 변경 사항과 함께 간단하게 작동합니다.
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
Firefox, Edge 및 ie 바이너리를 설정하는 데 동일하게 사용할 수 있습니다.
pycharm 커뮤니티 에디션과 동일한 상황이므로 cmd와 마찬가지로 경로 변수를 다시로드하려면 ide를 다시 시작해야합니다. 당신의 아이디어를 다시 시작하면 괜찮을 것입니다.
r
원시 문자열의 경우 문자열 앞에 문자로 시작하는 경로 문자열을 추가해야 합니다. 나는이 방법으로 테스트했으며 작동합니다.
driver = webdriver.Chrome(r"C:/Users/michael/Downloads/chromedriver_win32/chromedriver.exe")
PATH env를 사용하여 땜질을 피하기 위해이 스레드의 향후 독자를위한 추가 입력 / 설명 Windows 수준에서 변수를 설정하고 Windows 시스템을 다시 시작하십시오 ( Chrome에 해당하는 https://stackoverflow.com/a/49851498/9083077의 답변 복사 ).
(1) 이전에이 스레드에서 설명한대로 chromedriver를 다운로드하고 압축이 풀린 chromedriver.exe를 X : \ Folder \ of \ your \ choice에 놓습니다.
(2) 파이썬 코드 샘플 :
import os;
os.environ["PATH"] += os.pathsep + r'X:\Folder\of\your\choice';
from selenium import webdriver;
browser = webdriver.Chrome();
browser.get('http://localhost:8000')
assert 'Django' in browser.title
참고 : (1) 샘플 코드 (참조 된 답변에서)가 지정된 URL에 대한 Firefox 브라우저를 여는 데 약 5 초가 걸릴 수 있습니다. (2) 지정된 URL에서 이미 실행중인 서버가 없거나 문자열이 'Django'인 제목이있는 페이지를 제공하는 서버가 없으면 Python 콘솔에 다음 오류가 표시됩니다. assert 'Django'in browser.title AssertionError
chromedriver의 압축을 풀 때 나중에 추적 할 수 있도록 정확한 위치를 지정하십시오. 아래에서 OS에 적합한 크롬 드라이버를 얻은 다음 정확한 위치로 압축을 풀고 나중에 코드에서 인수로 제공 할 수 있습니다.
wget http://chromedriver.storage.googleapis.com/2.10/chromedriver_linux64.zip unzip chromedriver_linux64.zip -d /home/virtualenv/python2.7.9/
크롬 드라이버를 경로에 추가하기 전에 브라우저와 동일한 버전인지 확인하십시오.
그렇지 않은 경우 크롬 업데이트 / 다운 그레이드 및 웹 드라이버 업그레이드 / 다운 그레이드 버전과 일치해야합니다.
크롬 버전을 최대한 업데이트하고 웹 드라이버를 일치시키는 것이 좋습니다.
크롬을 업데이트하려면
- 오른쪽 상단에서 세 개의 점을 클릭하십시오.
- 클릭
help
->About Google Chrome
- 버전을 업데이트하고 크롬을 다시 시작하십시오.
그런 다음 http://chromedriver.chromium.org/downloads 에서 호환되는 버전을 다운로드 하십시오 .
참고 : 최신 Chromedriver가 항상 최신 Chrome 버전과 일치하지는 않습니다.
이제 PATH에 추가 할 수 있습니다 :
컴퓨터 어딘가에 웹 폴더를 배치 할 새 폴더를 만듭니다. 나는라는 폴더 생성
webdrivers
에를C:\Program Files
폴더 경로를 복사하십시오. 내 경우에는
C:\Program Files\webdrivers
마우스 오른쪽 버튼으로 클릭
this PC
->properties
:
- 오른쪽 클릭
Advanced System settings
- 딸깍 하는 소리
Environment Variables
- 에서을
System variables
클릭path
하고edit
- 딸깍 하는 소리
new
- 복사 한 경로를 붙여 넣기
- 모든 창에서 확인을 클릭하십시오
Thats it! I used pycharm and I had to reopen it. Maybe its the same with other IDEs or terminals.
If you are working with robot framework RIDE. Then you can download Chromedriver.exe
from its official website and keep this .exe file in C:\Python27\Scripts
directory. Now mention this path as your environment variable eg. C:\Python27\Scripts\chromedriver.exe
.
Restart your computer and run same test case again. You will not get this problem again.
According to the instruction, you need to include the path to ChromeDriver when instantiating webdriver.Chrome eg.:
driver = webdriver.Chrome('/path/to/chromedriver')
Could try to restart computer if it doesn't work after you are quite sure that PATH is set correctly.
In my case on windows 7, I always got the error on WebDriverException: Message: for chromedriver, gecodriver, IEDriverServer. I am pretty sure that i have correct path. Restart computer, all work
In my case, this error disappears when I have copied chromedriver file to c:\Windows folder. Its because windows directory is in the path which python script check for chromedriver availability.
If you are using remote interpreter you have to also check if its executable PATH is defined. In my case switching from remote Docker interpreter to local interpreter solved the problem.
Check you path for chrome driver, it might not get it from there. Simply Copy paste the driver location into the code.
I encountered the same problem as yours. I'm using PyCharm to write programs, and I think the problem lies in environment setup in PyCharm rather than the OS. I solved the problem by going to script configuration and then editing the PATH in environment variables manually. Hope you find this helpful!
Add the webdriver(chromedriver.exe or geckodriver.exe) here C:\Windows. This worked in my case
The best way is maybe to get the current directory and append the remaining address to it. Like this code(Word on windows. On linux you can use something line pwd): webdriveraddress = str(os.popen("cd").read().replace("\n", ''))+'\path\to\webdriver'
When I downloaded chromedriver.exe I just move it in PATH folder C:\Windows\System32\chromedriver.exe and had exact same problem.
For me solution was to just change folder in PATH, so I just moved it at Pycharm Community bin folder that was also in PATH. ex:
- C:\Windows\System32\chromedriver.exe --> Gave me exception
- C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.3\bin\chromedriver.exe --> worked fine
(for Mac users) I have the same problem but i solved by this simple way: You have to put your chromedriver.exe in the same folder to your executed script and than in pyhton write this instruction :
import os
os.environ["PATH"] += os.pathsep + r'X:/your/folder/script/'
'Programing' 카테고리의 다른 글
변수 유형을 매개 변수로 사용하는 C #의 제네릭 (0) | 2020.07.17 |
---|---|
현재 노드를 포함하는 jQuery find (..) 메소드를 찾고 있습니다. (0) | 2020.07.17 |
Resharper- 사용하지 않는 모든 클래스 찾기 (0) | 2020.07.17 |
장고 단위 테스트를 여러 파일로 분산시키는 방법은 무엇입니까? (0) | 2020.07.17 |
Java8 : java.lang.Object에서 메소드의 기본 메소드를 정의하는 것이 금지 된 이유 (0) | 2020.07.17 |