1

selenium uses "fake" browsers that Google sign-in rejects ("This browser app is not secure"), mechanize lacks a GUI, webbrowser can't click. Is there any package that can open the "usual" browser that won't be rejected by third-party services?


For reference, here's what happens if I try to supply the "usual" Firefox executable path to selenium:

from selenium import webdriver
exepath = r"C:\Program Files\Firefox Developer Edition\firefox.exe"
driver = webdriver.Firefox(executable_path=exepath)

The browser does open, but selenium fails to connect:

File "D:\Anaconda\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
self.service.start()
File "D:\Anaconda\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
self.assert_process_still_running()
File "D:\Anaconda\lib\site-packages\selenium\webdriver\common\service.py", line 111, in assert_process_still_running
% (self.path, return_code)

WebDriverException: Service C:\Program Files\Firefox Developer Edition\firefox.exe unexpectedly exited. 
Status code was: 0

I searched for this exact error - all solutions point back to using the "WebDriver" (i.e. "fake browser"). Tried also with Chrome - same deal, except it first waits 30 secs before throwing the error.


Note: geckodriver and ChromeDriver are both WebDrivers - the "fake" browsers.

Note 2: this is the message I'm getting: (and link to Learn more)

This is how WebDriver's URL appears:

enter image description here

4
  • There's also an ongoing discussion about this here: gist.github.com/ikegami-yukino/51b247080976cb41fe93 (Adding for reference). Seems like others are facing the same issue Feb 5, 2020 at 10:37
  • You can download geckdriver exe and give the path of it in executable path
    – Murthi
    Feb 5, 2020 at 10:41
  • @nopassport1 Right, I did notice a few "dev-stage" efforts, but I need a solution sooner - wish them luck regardless Feb 5, 2020 at 10:41
  • @Murthi I address this exact suggestion at the bottom of my post Feb 5, 2020 at 10:42

3 Answers 3

0

Selenium doesn't have "fake" browsers, it uses browsers installed on the machine. The executable_path is for geckodriver/ChromeDriver, not firefox.exe.

exepath = "path_to\geckodriver.exe"
driver = webdriver.Firefox(executable_path=exepath)
4
  • 1
    The browser is detected as "automated test software" by Google, and is rejected as insecure - so "fake" or not, it is a problem. Feb 5, 2020 at 10:41
  • @OverLordGoldDragon The insecure is on the url, not the browser. And you can remove the warning by adding FirefoxOptions() with option useAutomationExtension.
    – Guy
    Feb 5, 2020 at 10:46
  • As noted in my post, when I try to sign in, I am notified "This browser app is not secure" - and I cannot sign in; not just a warning. Feb 5, 2020 at 10:57
  • Also can't test your suggestion as I'm unsure how it's done exactly; opts=FirefoxOptions(); opts.add_argument('useAutomationExtension'); Firefox(options=opts) yields error: WebDriverException: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details. Feb 5, 2020 at 10:57
0

exepath need to path to geckodriver not firefox.

exepath = r"path\geckodriver.exe"


driver = webdriver.Firefox(executable_path=exepath)
1
  • This is the WebDriver I noted to be problematic in my question. Feb 5, 2020 at 11:51
0

A bit of more details about your usecase and why you felt Selenium uses fake browsers, would have helped us to construct a more canonical answer.

However to start with, this is the reason Why Firefox requires GeckoDriver and GeckoDriver scoops up a brand new moz:profile on the fly during each execution.

You can find a detailed discussion in Is it Firefox or Geckodriver, which creates “rust_mozprofile” directory


Error you are facing

This error message...

WebDriverException: Service C:\Program Files\Firefox Developer Edition\firefox.exe unexpectedly exited. 
Status code was: 0

...implies that the GeckoDriver was unable to initiate/spawn a new Browsing Context i.e. Firefox Browser session.


executable_path

executable_path is the parameter through which users can pass the absolute path of the GeckoDriver binary overriding the system path of GeckoDriver binary to be used for Firefox 47.0.1 and greater.

You can find a detailed discussion in What is the executable_path in Google Colaboratory for geckodriver?


This usecase

To supply the usual Firefox executable/binary path you need to use the binary property through an instance of FirefoxOptions() as follows:

from selenium import webdriver

binary = r'C:\Program Files\Firefox Developer Edition\firefox.exe'
options = webdriver.FirefoxOptions()
options.binary = binary
browser = webdriver.Firefox(firefox_options=options, executable_path=r'C:\path\to\geckodriver.exe')
browser.get('http://google.com/')

You can find a detailed discussion in How to open Firefox Developer Edition through Selenium


This browser app is not secure

There can be diverse reason bhind this error as follows:

Solution

In these cases the respective solution would be to:


Reference

You can find a couple of relevant detailed discussion in:

4
  • I'll read your sources - in the meantime, your suggestion didn't work; as far as what I see, nothing changed. I've updated my question. -- Regarding "fake" - simply per Google calling it "insecure" and the browser touting it "automated test software", so basically an incomplete, sandbox-like alternative rather than the "real thing" - but yes, I could be wrong. Feb 5, 2020 at 13:08
  • Couldn't fully interpret your links, but from what I understood, GeckoDriver is an "interface" between user input commands and the browser itself. Then ideally, Google shouldn't be complaining; whatever the case, something about Selenium's spawned browser is being seen differently on the receiving end. Feb 5, 2020 at 13:25
  • @OverLordGoldDragon Checkout the updated answer and let me know if you have any questions. Feb 5, 2020 at 13:38
  • The FirefoxBinary approach didn't work; I don't use TwoFactorAuthentication; all of my accounts fail. As for "allow less secure apps" - that's a rather unreasonable expectation on behalf of selenium; why should users expose themselves to security risks? I understand there may 'overreactions', but I don't know what the exact risks are, so I rather not tread that territory. Feb 5, 2020 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.