1

I want to open google chrome browser and go to facebook and terminate the python program but keep the google chrome window open until I manually close it. Please give me your own idea/Program with the above said as the aim.

I expect the chrome window to remain open after the program terminates, but it closes automatically after the program terminates.

3
  • Let me know about further clarification of the question. Commented Jun 13, 2019 at 6:11
  • Are you using selenium?
    – WiseDev
    Commented Jun 13, 2019 at 6:28
  • I tried with selenium. If you could provide code involving selenium ill try Commented Jun 13, 2019 at 6:44

2 Answers 2

3

Using os.system() should be avoided because it is platform dependent and because it isn't secure: if you use os.system('start chrome "%s"') % url where url is a string submitted by the user, someone can enter www.facebook.com" && shutdown /s /t "0 Facebook will open in a new Chrome window but then the computer will shut down.

The easiest way to open a new page in the browser is:

import webbrowser
webbrowser.open_new("www.facebook.com")

It remains open when the Python script terminates.

1
  • 1
    Security perspective makes absolute sense Commented Jun 13, 2019 at 7:02
0

Try this, works on windows!

import os
os.system("start chrome \"www.facebook.com\"")

This shall open a chrome browser with the Facebook URL using cmd and it remains open even after the termination of the program.

7
  • OMG Thanks it works. Can you give some code to open notepad, because it also opens and closes it if the program terminates Commented Jun 13, 2019 at 6:46
  • @KamaleshPathy You can use os.system("start notepad").
    – Maximouse
    Commented Jun 13, 2019 at 7:01
  • For that, you can use Subprocess as it provides more flexibility with outputs. subprocess.Popen(["Notepad"]) Commented Jun 13, 2019 at 7:03
  • @AkashGovind Agree, but I'm not sure if subprocesses remain alive when you exit the Python script. (But it seems that dhey do.)
    – Maximouse
    Commented Jun 13, 2019 at 7:11
  • @AkashGovind subprocess.Popen(["Notepad"]) still have the same problem Commented Jun 13, 2019 at 7:13

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.