Home > Blockchain >  Selenium Python code that used to work now opens browser and then gets stuck in "data:,".
Selenium Python code that used to work now opens browser and then gets stuck in "data:,".

Time:11-02

EDIT: I just realised that I reinstalled Chrome recently, so that might be the problem.

I think Selenium expects to find Chrome in Appdata, but it's not there. I tried copying the Application folder in C:\Program Files\Google\Chrome\ to C:\Users\hougy\AppData\Local\Google\Chrome but that doesn't fix it.

I also tried to show it where Chrome is installed but it also doesn't work:

options = webdriver.ChromeOptions()
options.binary_location = 'C:\Program Files\Google\Chrome\Application\chrome.exe'
browser = webdriver.Chrome(options=options)

I tried variations of the code above and none of them work.

Original question:

My code was working perfectly in the past few months. Then when I ran it yesterday, after downloading the new chromedriver, the browser opens but the webpage does not load, it gets stuck in address "data:,".

Here's a simplified version that has the same problem:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from lxml import etree
import csv
import time
from datetime import datetime
import requests

#options = webdriver.ChromeOptions()
#options.add_experimental_option('excludeSwitches', ['enable-logging'])
#options.add_argument('--no-sandbox')
#options.add_argument("start-maximized")
#browser = webdriver.Chrome(options=options)
browser = webdriver.Chrome()

quote = 'https://www.fundamentus.com.br/detalhes.php?papel=BBAS3'
browser.get(quote)

I tried replacing browser = webdriver.Chrome() with the code commented above it because some people here suggested it, but the results are the same. The only difference is that it seems to omit some error messages related to bluetooth that were always there and are not the cause of the problem.

I tried moving to the newest version of Python, then updating pip and redownloading all the libraries. I also updated Chrome and am using the latest stable chromedriver.

I tried running the code in my second PC and it works there with the same Python, Chrome, chromedriver and libraries versions.

Here's what I get when I run it:

python .\seleniumTest.py

DevTools listening on ws://192.168.0.104:63785/devtools/browser/5d07327b-ae87-49ee-be00-b9cb0f055b74
[5156:5772:1101/160103.660:ERROR:chrome_browser_main_extra_parts_metrics.cc(230)] crbug.com/1216328: Checking Bluetooth availability started. Please report if there is no 
report that this ends.
[5156:5772:1101/160103.664:ERROR:chrome_browser_main_extra_parts_metrics.cc(233)] crbug.com/1216328: Checking Bluetooth availability ended.
[5156:13960:1101/160103.681:ERROR:device_event_log_impl.cc(214)] [16:01:03.680] Bluetooth: bluetooth_adapter_winrt.cc:1073 Getting Default Adapter failed.
[5156:5772:1101/160103.690:ERROR:chrome_browser_main_extra_parts_metrics.cc(236)] crbug.com/1216328: Checking default browser status started. Please report if there is no 
report that this ends.
[5156:5772:1101/160103.714:ERROR:chrome_browser_main_extra_parts_metrics.cc(240)] crbug.com/1216328: Checking default browser status ended.
[5156:13960:1101/160126.589:ERROR:device_event_log_impl.cc(214)] [16:01:26.588] USB: usb_service_win.cc:258 Failed to get device driver name: Element not found. (0x490)
Traceback (most recent call last):
  File "C:\Users\hougy\OneDrive\Documentos\plij\seleniumTest.py", line 14, in <module>
    browser = webdriver.Chrome()
  File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
    super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 93, in __init__
    RemoteWebDriver.__init__(
  File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 266, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 357, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 418, in execute
    self.error_handler.check_response(response)
  File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
Stacktrace:
Backtrace:
        Ordinal0 [0x006006F3 2492147]
        Ordinal0 [0x00599BD1 2071505]
        Ordinal0 [0x004A2340 1057600]
        Ordinal0 [0x0049739D 1012637]
        Ordinal0 [0x004BFF64 1179492]
        Ordinal0 [0x004BC43B 1164347]
        Ordinal0 [0x004B9C9F 1154207]
        Ordinal0 [0x004E9DFF 1351167]
        Ordinal0 [0x004E9A6A 1350250]
        Ordinal0 [0x004E568B 1332875]
        Ordinal0 [0x004C21D4 1188308]
        Ordinal0 [0x004C302F 1191983]
        GetHandleVerifier [0x007867A6 1545030]
        GetHandleVerifier [0x0083105C 2243580]
        GetHandleVerifier [0x0068BC97 518199]
        GetHandleVerifier [0x0068AD80 514336]
        Ordinal0 [0x0059ED2D 2092333]
        Ordinal0 [0x005A2EE8 2109160]
        Ordinal0 [0x005A3022 2109474]
        Ordinal0 [0x005ACB71 2149233]
        BaseThreadInitThunk [0x76736359 25]
        RtlGetAppContainerNamedObjectPath [0x773187A4 228]
        RtlGetAppContainerNamedObjectPath [0x77318774 180]

CodePudding user response:

When you previously executed your program the browser and the ChromeDriver was in perfect sync. Hence it executed well.

But currently Google Chrome browser being updated to Version 95.0.4638.69 your program doesn't finds the matching ChromeDriver to drive the Chrome browser.

Hence you see data:, in the address bar.


Solution

Use the key executable_path to point to the downloaded matching version of the ChromeDriver as follows:

browser = webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')

CodePudding user response:

I couldn't solve it but discovered a workaround: using Firefox and geckodriver. I had many problems before whenever Chrome updated, so I hope this change will improve things because I only use Firefox for this.

  • Related