Im running a tiny script(See below).
Every time I run it I get: selenium.common.exceptions.TimeoutException: Message: Failed to read marionette port
I'm on Ubuntu 22, running Selenium 4, using Selenium-py. Any idea why this could be happening?
from selenium import webdriver
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.firefox.service import Service
def _make_options() -> webdriver.FirefoxOptions:
options = webdriver.FirefoxOptions()
options.add_argument("--no-sandbox")
options.add_argument("--headless")
options.add_argument("--remote-debugging-port=0")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-gpu")
options.add_argument("--disable-gpu-sandbox")
options.add_argument("--single-process")
return options
def _initialize_geckodriver() -> webdriver.Firefox:
options = _make_options()
driver = webdriver.Firefox(
service=Service(GeckoDriverManager().install())
,options=options,
)
return driver
_initialize_geckodriver()
Related
I got this error when running my code. BTW, I am running this behind a VPN.
Can anyone tell me how can I fix it?
BTW, I try --headless, but weird that only the default profile is started with headless.
selenium.common.exceptions.WebDriverException: Message: unknown error:
Chrome failed to start: exited normally. (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.)
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import os
os.environ['WDM_SSL_VERIFY'] = '0'
os.environ["HTTPS_PROXY"] = "http://127.0.0.1:4780"
options = webdriver.ChromeOptions()
options.add_argument("--no-sandbox")
# options.add_argument('--headless')
options.add_argument(r"--user-data-dir=C:\Users\nuc\AppData\Local\Google\Chrome\User Data") #e.g. C:\Users\You\AppData\Local\Google\Chrome\User Data
options.add_argument(r'--profile-directory=Profile 5') #e.g. Profile 3
# options.binary_location
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.switch_to.new_window('tab')
driver.get("https://www.youtube.com/")
driver.save_screenshot('ss.png')
Ok this may be very obv but I can't seem to figure out how to remove the logs in the selenium terminal. I have looked at most threads and found nothing. Thank you for your time :)
Code:
import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
# Hide the tons of logs
os.environ['WDM_LOG_LEVEL'] = '0'
options = Options()
options.add_argument("--headless")
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
time.sleep(1000)
Wanted Removed:
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
DevTools listening on ws://127.0.0.1:55488/devtools/browser/4bac099d-3e3b-40e6-a082-db3e95719f41```
This will run selenium in completely silent mode.
options = Options()
options.headless = True
options.add_experimental_option("excludeSwitches", ["enable-logging"])
I need to open web whatsapp but it gives me Deprecation Warning
here is the code
import selenium
from selenium import webdriver
import time
driver_path = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
driver = webdriver.Chrome(driver_path)
driver.get("https://web.whatsapp.com/")
driver.maximize_window()
time.sleep(20)
driver.quit
İts not giving me anything just opens Chrome
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
First you need download chromedriver - https://chromedriver.chromium.org/downloads
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import time
ser = Service('path_to\chromedriver.exe')
browser = webdriver.Chrome(service=ser)
browser.get('https://web.whatsapp.com/')
browser.maximize_window()
time.sleep(20)
browser.quit
You need to pass The driver_path to Service(). below should work for you.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
driver_path = r"chromdriver.exe full file path here"
service = Service(driver_path)
option = webdriver.ChromeOptions()
driver = webdriver.Chrome(service = service, options = option )
driver.get("https://web.whatsapp.com/")
driver.maximize_window()
time.sleep(20)
driver.quit
I am trying to open Brave using Selenium (in Python). It actually opens but then immediately closes with the following errors appearing in the console:
[23340:9252:1107/063438.209:ERROR:os_crypt_win.cc(93)] Failed to
decrypt: The parameter is incorrect. (0x57)
[23340:9252:1107/063438.210:ERROR:brave_sync_prefs.cc(114)] Decrypt
sync seed failure
DevTools listening on
ws://127.0.0.1:53809/devtools/browser/ecce3b0e-2884-4173-bdab-2215a3d7f507
[23340:9252:1107/063438.480:ERROR:CONSOLE(1)] "[Shields]: Can't
request shields panel data for tabId: 2. Error: No tab url
specified", source:
chrome-extension://mnojpmjdmbbfmejpflffifhffcmidifd/out/brave_extension_background.bundle.js
(1)
I've done some searching but couldn't really find anything helpful.
Here is my code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
class Selen:
def __init__(self):
options = Options()
service = Service("C:/Auxiliary/chromedriver_win32/chromedriver.exe")
options.binary_location = "C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe"
self.driver = webdriver.Chrome(service=service, options=options)
self.driver.get("https://google.com")
Selen()
I'm using Windows 11.
Firstly, do you have chrome installed, and secondly, does it work if you do this?
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
class Selen:
def __init__(self):
options = Options()
path = "C:/Auxiliary/chromedriver_win32/chromedriver.exe"
self.driver = webdriver.Chrome(executable_path=path, options=options)
self.driver.get("https://google.com")
time.sleep(20)
driver.close()
instance = Selen()
If it does work, try this to get it to work with brave,
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
class Selen:
def __init__(self):
options = Options()
options.binary_location = "C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe"
path = "C:/Auxiliary/chromedriver_win32/chromedriver.exe"
self.driver = webdriver.Chrome(executable_path=path, options=options)
self.driver.get("https://google.com")
time.sleep(20)
driver.close()
instance = Selen()
So I've been trying to get headless chrome working for days. I have no idea whats wrong !! I've tried everything I can find in the forums relating to the issue.
Right now this is the code im running (it's a direct snippet from someone else's tutorial which works fine for them):
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
browser_name = "chrome"
if browser_name == 'chrome':
options = webdriver.ChromeOptions()
options.headless = True
driver = webdriver.Chrome(executable_path=r"./chromedriver", options=options)
start_url = "https://google.com"
driver.get(start_url)
print(driver.page_source.encode("utf-8"))
driver.quit()
When I run that code I receive the following error
driver = webdriver.Chrome(executable_path=r"./chromedriver", options=options)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 64, in __init__
desired_capabilities = options.self.to_capabilities()
AttributeError: 'Options' object has no attribute 'self'
It might be worth knowing that the chromedriver is in the correct path, I know this because when I run:
browser_name = "chrome"
if browser_name == 'chrome':
driver = webdriver.Chrome(r"./chromedriver")
start_url = "https://google.com"
driver.get(start_url)
print(driver.page_source.encode("utf-8"))
driver.quit()
This works fine
There are two distinct approaches. If you are using:
options = webdriver.ChromeOptions()
Using only:
from selenium import webdriver
is sufficient.
But if you are using the following import:
from selenium.webdriver.chrome.options import Options
You have to use an instance of Options() to set the headless property as True as follows:
options = Options()
options.headless = True
driver = webdriver.Chrome(executable_path=r"./chromedriver", options=options)