'ImportError: cannot import name 'remote_connection' from 'selenium.webdriver.chrome'
When trying to import this library
from instaclient import InstaClient
I get the following error
C:\Users\localhost\Desktop\Bot>python bot.py
Traceback (most recent call last):
File "bot.py", line 11, in <module>
from instaclient import InstaClient
File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\instaclient\__init__.py", line 26, in <module>
from instaclient.client.instaclient import InstaClient
File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\instaclient\client\instaclient.py", line 28, in <module>
from instaclient.client.scraper import Scraper
File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\instaclient\client\scraper.py", line 26, in <module>
from instaclient.client.component import Component
File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\instaclient\client\component.py", line 20, in <module>
from instaclient.client.driver import HiddenChromeWebDriver
File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\instaclient\client\driver.py", line 12, in <module>
from selenium.webdriver.chrome import service, webdriver, remote_connection
ImportError: cannot import name 'remote_connection' from 'selenium.webdriver.chrome' (C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\chrome\__init__.py)
Environment:
Python 3.7.8
Selenium 4.1
InstaClient 2.9
Solution 1:[1]
Importing InstaClient is not the issue, it is with the selenium imports
You cannot import webdriver and remote using from selenium.webdriver.chrome import service, webdriver, remote_connection
as detailed in the following exception:
ImportError: cannot import name 'remote_connection' from 'selenium.webdriver.chrome' (C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\chrome\__init__.py)
You need to import webdriver separately
from selenium import webdriver
You require service only if you are using a locally installed driver for selenium automation using a browser on your local machine, for example
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
options = webdriver.ChromeOptions()
service = ChromeService(executable_path'/usr/local/bin/chromedriver')
driver = webdriver.Chrome(service=service, options=options)
If you require selenium automation using a remote server hosting browsers like selenium grid, see following example
from selenium import webdriver
options = webdriver.ChromeOptions()
driver = webdriver.Remote(
command_executor="<server_address>",
options=options
)
driver.get("http://www.google.com")
driver.quit()
Where <server_address> would be something like http://192.168.1.100:4444/wd/hub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |