Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

12296:26672:0420/163936.459:ERROR:browser_switcher_service.cc(238) XXX Init() Error in "Selenium Python"

I am using Version 81.0.4044.113 (Official Build) (64-bit). It was not happening before and the code was working completely fine. But after few days I ran it again and this error came.

I am using these modules->

from selenium import webdriver
from selenium.webdriver.common.by import By 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC 
from selenium.common.exceptions import TimeoutException
import csv
import time
from tkinter import *

def Authorization():
    time.sleep(15)
    username = driver.find_element_by_id("userInput")
    username.send_keys('username')
    driver.find_element_by_xpath("//*[@id='login-button']").click()

    time.sleep(5)
    password = driver.find_element_by_xpath("//*[@id='passwordInput']")
    password.send_keys('password')

    submit_button = driver.find_element_by_xpath("//*[@id='login-button']").click()

def Extractor():
    time.sleep(25)
    integrated_release = driver.find_elements_by_xpath("//*[@id='versionArea']/div/table/tbody/tr[2]/td[2]")
    global integrated_release_data
    integrated_release_data = [x.text for x in integrated_release]

    impact_release = driver.find_elements_by_xpath("//*[@id='versionArea']/div/table/tbody/tr[5]/td[2]")
    global impact_release_data 
    impact_release_data = [x.text for x in impact_release]

    build_platform = driver.find_elements_by_xpath("//*[@id='btkArea']/div/table/tbody/tr[2]/td[2]/span")
    global build_platform_data 
    build_platform_data = [x.text for x in build_platform]


def To_csv():
    csvData = [final_data]
    with open('data.csv', 'a') as csvFile:
        writers = csv.writer(csvFile)
        writers.writerows(csvData)
    csvFile.close()

def printtext():
    global bugName
    bugName = e.get() 
    print(bugName)

def kinter():
    root = Tk()
    root.geometry("500x100")
    root.title('xtractor')

    var = StringVar()
    label = Label( root, textvariable=var)
    var.set("Enter")
    label.pack()

    global e
    e = Entry(root)
    e.pack()
    e.focus_set()

    b = Button(root,text='submit',command=printtext)
    b.pack(side='bottom')
    root.mainloop()

kinter()

driver = webdriver.Chrome()

bugs = bugName.split(',')

driver.get("http........"+bugs[0])
bugname = [bugs[0]]

Authorization()
Extractor()
final_data = a+b+c+d+e
To_csv()

count = 0
for bug in bugs:
    try:
        if count == 0:
            count += 1
            continue

        driver.get("http:....."+bug)
        bugname = [bug]

        Extractor()
        final_data = a+b+c+d+e
        To_csv()
    except:
        continue

and I have installed the same version of webdriver as of chrome. Any idea how can I solve this issue?

like image 819
Aditya Sinha Avatar asked Apr 20 '20 11:04

Aditya Sinha


3 Answers

This error message...

ERROR:browser_switcher_service.cc(238)] XXX Init()

...implies that call to on_init_ raised an error.


Analysis

This error is defined in bluetooth_adapter_winrt.cc and was the direct impact of the changes incorporated within google-chrome as per the details available within the discussion Chrome no longer accepts certificates that fallback to common name


Solution

Ensure that:

  • Selenium is upgraded to current levels Version 3.141.59.
  • ChromeDriver is updated to current ChromeDriver v84.0 level.
  • Chrome is updated to current Chrome Version 84.0 level. (as per ChromeDriver v84.0 release notes)
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.

Additional considerations

However it was observed that this error can be supressed by running Chrome as root user (administrator) on Linux. but that would be a deviation from the documentation in ChromeDriver - WebDriver for Chrome where it is mentioned:

A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing '--no-sandbox' flag when creating your WebDriver session, i.e. the ChromeDriver session as such a configuration is unsupported and highly discouraged.

Ideally, you need to configure your environment to run Chrome as a regular user instead.


Suppressing the error

Finally, as per the documentation in Selenium Chrome Driver: Resolve Error Messages Regarding Registry Keys and Experimental Options these error logs can be supressed by adding the argument:

excludeSwitches: ['enable-logging']

So your effective code block will be:

from selenium import webdriver

options = webdriver.ChromeOptions() 
options.add_experimental_option("excludeSwitches", ["enable-logging"])
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://www.google.com/")
like image 148
undetected Selenium Avatar answered Oct 21 '22 09:10

undetected Selenium


I use Version 81.0.4044.113 (Official Build) (64-bit),too. and the same happens i encounter but it still run successfully. and now i still find to solve this problem!

like image 1
Ian.qiu Avatar answered Oct 21 '22 11:10

Ian.qiu


I had the same problem i tried alot but could not find the answer i needed the best thing i came up with to solve the error is to change your webdriver to geckodriver and use firefox instead of chrome

i hope this helped

like image 1
Ralph Avatar answered Oct 21 '22 11:10

Ralph