I am trying to launch opera using python selenium libraries. But getting capabilities error.
Codes I have tried:
Code1:
driver = webdriver.Opera()
driver.get('https://www.google.com')
Code2:
driver = webdriver.Opera(r'path to operadriver.exe')
driver.get('https://www.google.com')
Code3:
options = Options()
options.binary_location = r'C:\Opera\launcher.exe'
driver = webdriver.Opera(options=options)
driver.get('https://www.google.com')
Output:
Code1:
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary
Code2:
selenium.common.exceptions.WebDriverException: Message: Desired Capabilities must be a dictionary
Code3:
[20904:3220:0120/034255.122:ERROR:os_crypt_win.cc(61)] Failed to decrypt: The parameter is incorrect. (0x57)
DevTools listening on ws://127.0.0.1:59016/devtools/browser/0bb7bc3c-4b9a-451a-a736-a02a63feba7a
[20904:3220:0120/034255.673:ERROR:CONSOLE(0)] "Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.", source: chrome://startpage/ (0)
[20904:3220:0120/034255.674:ERROR:CONSOLE(0)] "Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.", source: chrome://startpage/ (0)
[20904:3220:0120/034255.675:ERROR:CONSOLE(0)] "Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.", source: chrome://startpage/ (0)
Only with code 3 the Opera browser launchers. But URL doesn't opens.
As I am able to launch chrome with similar codes.
This error message...
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary
and this error message...
selenium.common.exceptions.WebDriverException: Message: Desired Capabilities must be a dictionary
and this error message...
[20904:3220:0120/034255.122:ERROR:os_crypt_win.cc(61)] Failed to decrypt: The parameter is incorrect. (0x57)
...implies that the OperaDriver was unable to initiate/spawn a new Browsing Context i.e. Opera Browser session.
Solution
First of all you need to ensure that, you have downloaded the latest OperaChromiumDriver from operasoftware / operachromiumdriver. As per OperaDriver for Chromium-based Opera releases:
OperaChromiumDriver is a WebDriver implementation derived from ChromeDriver and adapted by Opera that enables programmatic automation of Chromium-based Opera products for desktop and Android platforms. It is a part of the Selenium project.
OperaChromiumDriver can be used without extra setup on Chromium-based versions of Opera starting from version 26.
Use both the arguments:
binary_location for opera binary and
executable_path for operadriver binary
Code Block:
from selenium import webdriver
from selenium.webdriver.opera.options import Options
options = Options()
options.binary_location = r'C:\Opera\launcher.exe'
driver = webdriver.Opera(options=options, executable_path=r'C:\path\to\operadriver.exe')
driver.get("http://google.com/")
This worked for me:
from selenium import webdriver
from selenium.webdriver.opera.options import Options
options = Options()
driver = webdriver.Opera(options=options)
driver.get("https://www.google.com")
I also get the same errors you showed but the URLs I need to open are being loaded automatically in Opera without issue.
You need to make sure your opera version matches the version of the driver.
check it by opening opera and enter this: opera://about
Ensure the operadriver.exe is on the same folder of the python script.
The driver can be downloaded here:
https://github.com/operasoftware/operachromiumdriver/releases
Related
I'm trying to perform a fairly simple action using Selenium, namely opening google images in Firefox browser.
I also use a proxy server running on the localhost.
from selenium.webdriver import Firefox, FirefoxOptions
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.common.proxy import Proxy, ProxyType
options = FirefoxOptions()
service = Service()
options.add_argument("--headless")
options.accept_insecure_certs = True
proxy = Proxy({
'httpProxy': proxy_addr,
'sslProxy': proxy_addr,
'proxyType': ProxyType.MANUAL
})
options.proxy = proxy
b = Firefox(service=service, options=options)
b.execute("get", {'url': 'http://images.google.com'})
But unfortunately, I'm getting an error like this:
selenium.common.exceptions.WebDriverException: Message: Reached error
page:
about:neterror?e=contentEncodingError&u=https%3A//images.google.com/%3Fgws_rd%3Dssl&c=UTF-8&d=The%20page%20you%20are%20trying%20to%20view%20cannot%20be%20shown%20because%20it%20uses%20an%20invalid%20or%20unsupported%20form%20of%20compression.
I would be very grateful for any thoughts and advice what exactly might be the problem and at least approximately what should be paid attention to.
I'm using:
debian
firefox-esr
selenium == 4.2.0
geckodriver-v0.31.0
This error message...
selenium.common.exceptions.WebDriverException: Message: Reached error page: about:neterror?e=contentEncodingError&u=https%3A//images.google.com/%3Fgws_rd%3Dssl&c=UTF-8&d=The%20page%20you%20are%20trying%20to%20view%20cannot%20be%20shown%20because%20it%20uses%20an%20invalid%20or%20unsupported%20form%20of%20compression.
...implies that there are some configuration settings mismatch while GeckoDriver initiates/spawns a new Browsing Context i.e. firefox session and is often observed as:
Solution
As per the mozilla support docs you need to try out the following steps:
Try to reset the network.http.accept-encoding prefs on the about:config page in case they show as user set (bold). You can open the about:config page via the location/address bar. You can accept the warning and click "I'll be careful" to continue.
If you are having Avast Antivirus or Malwarebytes installed, you may need to disable those in the test machine before executing the tests.
I got this while running the selenium webdriver script in python I also set the path in System Environment and also tried downloading the webdriver that matches with my chrome version. And also letest version also. But I still get this error:
[8552:6856:1120/155118.770:ERROR:device_event_log_impl.cc(211)] [15:51:18.771] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[8552:6856:1120/155118.774:ERROR:device_event_log_impl.cc(211)] [15:51:18.774] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[8552:6856:1120/155118.821:ERROR:device_event_log_impl.cc(211)] [15:51:18.821] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
I used this in my code :
driver = webdriver.Chrome(resource_path("C:\\webdriver\\chromedriver.exe")) # to open the chromebrowser
driver.get("https://web.whatsapp.com")
This is a chromedriver issue that they're still working the kinks out of. I'm not entirely sure what's causing it, but the technical details seem to be detailed in Debanjan's answer.
The general solution on the internet just seems to be "ignore it", but it sure clutters up the logs a lot.
I did find a way to get it to shut up though (as well as the "DevTools" warning that pops up a lot as well).
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(options=options)
You can add your other chromedriver options and switches onto that as well, in addition to pointing to your chromedriver executable if you wish.
This error message...
[14432:11656:1120/161059.539:ERROR:device_event_log_impl.cc(211)] [16:10:59.539] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
...implies that the ChromeDriver raised an error while in trying to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
Analysis
This error occurs due to an USB device which is attached to the windows-10 system and isn't functioning properly.
This error is defined within usb_device_handle_win.cc as follows:
void UsbDeviceHandleWin::GotDescriptorFromNodeConnection(
TransferCallback callback,
scoped_refptr<base::RefCountedBytes> request_buffer,
scoped_refptr<base::RefCountedBytes> original_buffer,
Request* request_ptr,
DWORD win32_result,
size_t bytes_transferred) {
std::unique_ptr<Request> request = UnlinkRequest(request_ptr);
if (win32_result != ERROR_SUCCESS) {
SetLastError(win32_result);
USB_PLOG(ERROR) << "Failed to read descriptor from node connection";
std::move(callback).Run(UsbTransferStatus::TRANSFER_ERROR, nullptr, 0);
return;
}
Solution
This error isn't harmful and doesn't blocks the spawning of the new Browsing Context i.e. Chrome Browser session. So you can safely ignore the error.
However in your code block you need to replace the keyword resource_path with executable_path and your effective code block will be:
webdriver.Chrome(executable_path=r'C:\webdriver\chromedriver.exe') # to open the chromebrowser
driver.get("https://web.whatsapp.com")
References
You can find a couple of relevant detailed discussions in:
USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection error with ChromeDriver v87 / Chrome v87 using Selenium on Windows10
Failed to read descriptor from node connection: A device attached to the system is not functioning error using ChromeDriver Chrome through Selenium
After a week of finding an answer to my error, I ended up with a solution that you just need to install pywin32 library and it will not gives you an error
open cmd and type
pip install pywin32
and you are good to go.....!
Solution:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time
options = Options()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(executable_path=r"D:\SW\chromedriver90\chromedriver.exe",chrome_options=options)
url = 'https://carlsagan.com/'
driver.get(url)
...
driver.quit()
i found a fix!! first download this chrome extension then click the extension, and set the user-agent to "Chrome on Mac"
second change this line in your code
driver = webdriver.Chrome(resource_path("C:\\webdriver\\chromedriver.exe")) # to open the chromebrowser
driver.get("https://web.whatsapp.com")
to:
driver = webdriver.Chrome(executable_path=r'C:\webdriver\chromedriver.exe') # to open the chromebrowser
driver.get("https://web.whatsapp.com")
also open cmd and type:
pip install pywin32
check your device list to see if there is any usb devices doesn't work.
I solved this after My laptop have been enabled bluetooth and cam devices.
The error is probably because you have used parenthesis in the resource_path variable.
The code should be as following:
driver = webdriver.Chrome(resource_path="C:\webdriver\chromedriver.exe") # to open the chromebrowser
driver.get("https://web.whatsapp.com")
if still there is any problem you can try keeping the web driver in the same folder as the python file.
The error
[15292:18896:0820/144926.111:ERROR:device_event_log_impl.cc(214)] [14:49:26.110] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
disappeared after downloading and using the required web driver version for my chrome version I have installed. See https://chromedriver.chromium.org/downloads
options.add_experimental_option("excludeSwitches", ["enable-logging"]) did the trick for me without having to install pywin32.
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=chrome_options)
This worked for me, hope it helps someone.
I have tried many methods, but none has worked for me.
All I can do is delay the automatic exit of the Chrome browser with time modue.
from selenium import webdriver
import chromedriver_binary # Adds chromedriver binary to path
import time
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
driver = webdriver.Chrome(options=options)
driver.get('https://www.google.com/')
time.sleep(3600) # let the browser die after 1 hour
Please check the spec file name once . I have renamed the spec file but forget to update it in config file so getting this error . Later I changed . It solved
I want to use Selenium (installed: ver 3.141.0.dist-info) on Python (3.8) which is installed on my Windows 7 64,
I Use Brave Browser Version 1.17.73 Chromium: 87.0.4280.67 (Official Build) (64-bit)
and
Chromedriver (chromedriver_win32-87.0.4280.20) for it,
when running the following Py file which I got the code from here, new Brave browser opens up, but I get errors.
Any solution to make this works?
Appreciate your help.
when running this file:
from selenium import webdriver
driver_path = 'C:/python/Python38/chromedriver.exe'
brave_path = 'C:/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe'
option = webdriver.ChromeOptions()
option.binary_location = brave_path
browser = webdriver.Chrome(executable_path=driver_path, chrome_options=option)
browser.get("https://www.google.es")
get these errors:
c:/Users/mycomp/Desktop/Python/test/getwebdriver.py:12: DeprecationWarning: use options instead of
chrome_options
browser = webdriver.Chrome(executable_path=driver_path, chrome_options=option)
[7132:3952:1127/003249.595:ERROR:os_crypt_win.cc(93)] Failed to decrypt: The parameter is incorrect.
(0x57)
[7132:3952:1127/003249.596:ERROR:brave_sync_prefs.cc(114)] Decrypt sync seed failure
DevTools listening on ws://127.0.0.1:51576/devtools/browser/a048c130-e608-4ec6-a388-ad67fc32d97a
[1127/003250.360:ERROR:gl_surface_egl.cc(773)] EGL Driver message (Error) eglQueryDeviceAttribEXT:
Bad attribute.
[1127/003250.452:ERROR:gl_surface_egl.cc(773)] EGL Driver message (Error) eglQueryDeviceAttribEXT:
Bad attribute.
[1127/003250.455:ERROR:gl_surface_egl.cc(773)] EGL Driver message (Error) eglQueryDeviceAttribEXT:
Bad attribute.
[1127/003250.457:ERROR:gl_surface_egl.cc(773)] EGL Driver message (Error) eglQueryDeviceAttribEXT:
Bad attribute.
[1127/003250.458:ERROR:gl_surface_egl.cc(773)] EGL Driver message (Error) eglQueryDeviceAttribEXT:
Bad attribute.
[1127/003250.711:ERROR:gl_surface_egl.cc(773)] EGL Driver message (Error) eglQueryDeviceAttribEXT:
Bad attribute.
[1127/003250.821:ERROR:gl_surface_egl.cc(773)] EGL Driver message (Error) eglQueryDeviceAttribEXT:
Bad attribute.
[1127/003252.062:ERROR:gl_surface_egl.cc(773)] EGL Driver message (Error) eglQueryDeviceAttribEXT:
Bad attribute.
[1127/003254.498:ERROR:gl_surface_egl.cc(773)] EGL Driver message (Error) eglQueryDeviceAttribEXT:
Bad attribute.
C:\Users\mycomp\Desktop\Python\test>[1127/003304.647:ERROR:gl_surface_egl.cc(773)] EGL Driver message
(Error) eglQueryDeviceAttribEXT: Bad attribute.
Edited:
I found a solution to this from another place, to add the following to the code, but I still get errors, fewer errors
option.add_argument('--disable-gpu')
I run it and got this error:
c:/Users/mycomp/Desktop/Python/test/getwebdriver.py:12: DeprecationWarning:
use options instead of chrome_options
browser = webdriver.Chrome(executable_path=driver_path,
chrome_options=option)
[6208:8532:1127/021046.062:ERROR:os_crypt_win.cc(93)] Failed to decrypt: The
parameter is incorrect. (0x57)
[6208:8532:1127/021046.063:ERROR:brave_sync_prefs.cc(114)] Decrypt sync seed
failure
DevTools listening on ws://127.0.0.1:53262/devtools/browser/adb0a87d-298a-
4b9c-ad00-132a607cb9bd
%20%20browser-with-python-selenium-and-chromedriver
The key chrome_options was deprecated sometime back. Instead you have to use options and your effective code block will be:
from selenium import webdriver
driver_path = 'C:/python/Python38/chromedriver.exe'
brave_path = 'C:/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe'
option = webdriver.ChromeOptions()
option.binary_location = brave_path
browser = webdriver.Chrome(executable_path=driver_path, options=option)
browser.get("https://www.google.es")
References
You can find a couple of relevant detailed discussion in:
DeprecationWarning: use options instead of chrome_options error using ChromeDriver and Chrome through Selenium on Windows 10 system
How to initiate Brave browser using Selenium and Python on Windows
So, this is the code I'm having troubles with:
def scrap():
options = webdriver.ChromeOptions();
options.add_argument('headless');
options.add_argument('--profile-directory=Profile 1')
options.add_argument("--user-data-dir=C:/Users/omarl/AppData/Local/Google/Chrome/User Data/")
options.add_argument("--remote-debugging-port=45447")
options.add_argument("--disable-gpu")
browser = webdriver.Chrome(executable_path=r"C:\Users\omarl\OneDrive\Escritorio\chromedriver.exe", options=options)
scrapURL = "https://es.wallapop.com/search?distance=30000&keywords=leggins&latitude=41.38804&longitude=2.17001&filters_source=quick_filters"
browser.get(scrapURL)
#...
And the error:
WebDriverException: unknown error: unable to discover open pages
I don't have any instances of chrome when I execute the script, and when I'm using it without the headless option it works fine. Any idea why this is happening? Please, note that I'm using the --remote-debuggin-port provided in similar questions.
I'm using ChromeDriver 86.0.4240.22
To invoke a Chrome Profile in Headless mode you can use the --user-data-dir argument only and you can safely remove --profile-directory argument as follows:
Code Block:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--window-size=1920,1080')
# options.add_argument('--profile-directory=Profile 1')
options.add_argument(r"--user-data-dir=C:\Users\Soma Bhattacharjee\AppData\Local\Google\Chrome\User Data\Default")
options.add_argument("--remote-debugging-port=9222")
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get('https://www.google.com/')
print("Chrome Headless launched")
Console Output:
DevTools listening on ws://127.0.0.1:9222/devtools/browser/93c67c41-e125-4d12-abc0-fcf0f07a62f4
Chrome Headless launched
References
You can find a couple of relevant detailed discussions in:
How to open a Chrome Profile through --user-data-dir argument of Selenium
Selenium: Point towards default Chrome session
Additional Considerations
Ensure that:
Selenium is upgraded to current released Version 3.141.0.
ChromeDriver is updated to current ChromeDriver v86.0 level.
Chrome is updated to current Chrome Version 86.0 level. (as per ChromeDriver v86.0 release notes).
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
tl; dr
ChromeDriver remote debug port reservation race conditions
Have you tried using arg --no-sandbox?
A lot of people on Chrome Driver Error using Selenium: Unable to Discover Open Pages have had success with that argument.
I am trying to save a screenshot of a webpage, to do so I am trying to use Selenium. The problem is that once the webpage is opened, it stays blank with "data:" in the URL.
Here is my code:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options,executable_path='aPath/chromedriver.exe',service_log_path='aPath/mylog.txt')
driver.get('http://myURL.html')
screenshot=driver.save_screenshot('aPath/my_screenshot.png')
driver.quit()
NB: I have checked that my chromedriver version is compatible with my chrome browser version.
You need to update the value of the Key executable_path with the absolute path of the chromedriver binary and service_args as follows:
driver = webdriver.Chrome(options=options,executable_path=r'C:\path\to\chromedriver.exe', service_args=["--log-path=C:\\path\\to\\mylog.log"])
You can find a couple of relevant discussions in:
Selenium doesn't open the specified URL and shows data:,
What are 'service_args' for the selenium-python chrome webdriver?
Thanks for your help guys, actually Guy was right, I had to specify the port:
options.add_argument('--remote-debugging-port=9222')
Now it works!
I found that adding the following option worked for me:
options.add_argument('--no-sandbox')
Details found in this answer:
selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open pages using ChromeDriver through Selenium