Python Forum
VoiceControlBrowsers: Need help with selenium {adding user profiles}
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VoiceControlBrowsers: Need help with selenium {adding user profiles}
#1
Hi all,

Here my project.

I'm using selenium, gtts and speechrecognition to add voice interface to the browsers. Right now I'm using api.ai machine learning bot to process the speech. Currently, it works with chrome and firefox[default profile].

My problems.
1- Loading User profile in chrome with selenium.
I tried:
#CHROME
Chrome_UserData_Dir = "C:\\Users\\{user name}\\AppData\\Local\\Google\\Chrome\\User Data"
chrome_options = Options()
chrome_options.add_argument("user-data-dir=" + Chrome_UserData_Dir)
self.browser = webdriver.Chrome(chrome_options=chrome_options)
Error:
self.browser = webdriver.Chrome(chrome_options=chrome_options) File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__ desired_capabilities=desired_capabilities) File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 140, in __init__ self.start_session(desired_capabilities, browser_profile) File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 229, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 297, in execute self.error_handler.check_response(response) File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed (Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform=Windows NT 10.0.15063 x86_64)
Though the browser opens with my profile loaded, the program than crashes giving that error.

2- Loading User profile in Firefox with selenium.
Firefox_UserData_Dir = 'path to firefox profile'
firefox_profile = webdriver.FirefoxProfile(Firefox_UserData_Dir)
self.browser = webdriver.Firefox(firefox_profile=firefox_profile)
It runs but the behaviour is strange. eg- It opens new window intead of new tab.

3- My third problem is optimisation.
I need help optimizing this project and reducing too many if-else statements.


PS: feel free to contribute to this open source project
Reply
#2
UPDATE: I solved the first issue of Chrome crashing if a user profile is loaded, by killing every chrome.exe or chromedriver.exe process before calling selenium webdriver.

def kill_chrome_process():
    import psutil
    for p in psutil.process_iter():
        try:
            if p.name() in ['chrome.exe', 'chromedriver.exe']:
                p.kill()
        except psutil.Error:
            pass
But Firefox isn't working properly when user profile is loaded.

I wonder if I was right choosing Selenium instead of some GUI automation library like PyWinAuto.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,587 Nov-03-2017, 08:41 PM
Last Post: metulburr
  Saving username as first name while adding user in django admin prithvi 0 4,354 Aug-10-2017, 06:50 PM
Last Post: prithvi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020