I am making a bot to scrap me some information from the web via chromedriver. But because this information is sometimes limited to an account (like instagram insights) i need to use several UserData-Folders to save all the logins etc for the chromedriver. To save some memory I made a function "init" which initializes a chromedriver window with the desired UserData-Folder.
the function:
def init(userdata):
global driver
warnings.filterwarnings("ignore", category=DeprecationWarning)
option = Options()
option.add_argument("--disable-infobars")
option.add_argument("window-size=fullscreen")
option.add_argument("--disable-extensions")
option.add_argument("--log-level=3")
option.add_argument("--headless")
option.add_argument(r'--user-data-dir=dir\to\UserData' + str(userdata))
option.add_experimental_option("prefs", {"profile.default_content_setting_values.notifications": 1})
driver = webdriver.Chrome(chrome_options=option, executable_path='C:\Windows\chromedriver.exe')
when running the code without headless, it works like a charm. However when using headless it gives the following error:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: was killed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
chrome_options have been deprecated for quite some time now. Instead you have to use options as follows:
driver = webdriver.Chrome(options=option, executable_path='C:\Windows\chromedriver.exe')
Related
I have this script that was able to connect to a browser that is run by this command:
"c:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --remote-debugging-port=9222. For some reason, it stopped working.
from selenium import webdriver
from selenium.webdriver.edge.options import Options
edge_options = Options()
edge_options.add_experimental_option('debuggerAddress', '127.0.0.1:9222')
driver = webdriver.Edge(options=edge_options)
driver.get(youtube.com)
print(driver.title)
Part of the error message is this:
Message: unknown error: cannot connect to microsoft edge at 127.0.0.1:9222
from chrome not reachable
Two questions about this message:
Could I just connect to the IP address of the "real" browser?
Why is there written chrome instead of chromium?
This is a full error message it makes me swallow.
https://i.stack.imgur.com/mGL4d.png
I'm trying to connect selenium to an already open Google Chrome window in the following way:
options.add_experimental_option('debuggerAddress', 'localhost:9112')
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
options.add_argument('--disable-browser-side-navigation')
options.add_argument('--disable-gpu')
options.add_argument('enable-automation')
self.d = webdriver.Chrome(executable_path=r'C:\Users\Administrator\Desktop\chromedriver.exe', options=options)
By first calling Google Chrome from the command line:
chrome.exe --remote-debugging-port=9112 --user-data-dir="C:\selenum\AutomationProfile"
At first it's working fine, driver does his thing, but as soon as I logged out of the server and, of course, can't see browser window, Selenium also stops seeing it and raising errors
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable (Session info: chrome=105.0.5195.102)
no such window: target window already closed from unknown error: web view not found (Session info: chrome=105.0.5195.102)
The interesting thing is that when I switch back to the remote machine, the browser loads and continues to work.
I also tried to add
options.add_experimental_option("detach", True)
But it didn't solve the problem. When I run selenium in normal way without command line, debugging and other stuff then it works stable, but I need to handle an already opened Google Chrome window.
This bug occurred out of nowhere in a program that previously functioned perfectly. I'm absolutely certain I have not done any changes on the program since it's functionality was perfect, so this is by far the weirdest and most frustrating bug I have ever experienced.
This is the code I'm trying to execute:
chrome_options.add_extension('C:\\chromedriver\\ModHeader_v (1).crx')
chrome_options.add_argument('--proxy-server=socks5://' + '127.0.0.1:9150')
driver = webdriver.Chrome('C:\\chromedriver\\chromedriver.exe', chrome_options = chrome_options)
Which raises the following error:
selenium.common.exceptions.WebDriverException: Message: unknown
error: failed to wait for extension background page to load:
chrome-extension://idgpnmonknjnojddfkpgkljpfnnfcklj/_generated_background_page.html
from timeout: Timed out receiving message from renderer: 10.000
(Driver info: chromedriver=2.24.417431
(9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT
10.0.15063 x86_64)
I assume that a change within the Tor browser is causing this bug. There is no other potential cause.
I ran into this same error message. Downloading the latest version of chromedriver fixed it for me. (New version released 19 days ago: https://sites.google.com/a/chromium.org/chromedriver/downloads)
Try to use Seleniumwire, for example:
from seleniumwire import webdriver
def set_chrome_driver():
options = webdriver.ChromeOptions()
options.add_argument("--start-maximized")
options.add_argument("--disable-infobars")
options.add_argument("--no-proxy-server")
driver = webdriver.Chrome(executable_path=r'C:\Automation_package\chromedriver.exe')
driver.get('http://172.1.1.1:5000/path/api/')
driver.header_overrides = {"iv-user": "Admin", "iv-groups": "SuperAdmin", "iv-roles": "Viewers",}
driver.get('http://172.1.1.1:5000/path/api/')
I received this error: "WebDriverException: Message: 'chromedriver' executable needs to be in PATH."
The only way I was able to fix it was to manually add one of the locations of chromedriver like this:
driver = webdriver.Chrome("/Users/anncolvin/.rvm/bin/chromedriver")
After Chrome launched, I then received this error: "You are using an unsupported command-line flag: --ignore-certifcate-errors. Stability and security will suffer."
I'd like to try using the following code to address this new error but I don't know how/if I can combine it with manually specifying chromedriver's location?
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["ignore-
certificate-errors"])
browser = webdriver.Chrome(chrome_options=options)
browser.get("http://google.com/")
All you have to do is specify the webdriver location as an argument when calling the Chrome webdriver like so:
chrome_path = r"/Users/anncolvin/.rvm/bin/chromedriver"
browser = webdriver.Chrome(chrome_path, chrome_options=options)
I am trying to use selenium with chrome web driver. When I run it without the options it works fine:
>>>driver = webdriver.Chrome(executable_path=path)
but when I add options (loaded profile) like this:
>>> options = webdriver.ChromeOptions()
>>> options.add_argument('--user-data-dir=%s' % chromeProfile)
>>> driver = webdriver.Chrome(executable_path=path,chrome_options=options)
it starts the browser window, which seems alive, but the command hangs until it finally declares:
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: u'unknown error: Chrome failed to start: exited normally\n (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)'
what could be causing this problem and how can I go about debugging it?
Thanks
OK - figured it out. The problem seems to be that one profile cant be opened while trying to connect a webdriver to it. I copied the default profile to a new location, and now it works fine. I'll leave this here in case this is useful to anyone.