python stop selenium standalone server
Question: How would I stop the selenium-server-standalone. I know you can start it by
`java -jar selenium-server-standalone.jar` But how would you stop it? Also, is
there a simple way to script it in python to start and stop it as I am running
tests.I feel like this is pretty simple. But am unable to find the answer to
my question.


Answer: You can start the server with `subprocess.Popen`, and shut it down with
`sel.shut_down_selenium_server()`:

    
    
    import selenium
    import socket
    import subprocess
    import shlex
    import sys
    import time
    
    # CHANGE path='/path/to/selenium-server.jar' AS NEEDED:
    def start_server(path='/path/to/selenium-server.jar'):
        null=open('/dev/null')
        proc=subprocess.Popen(shlex.split('java -jar {p}'.format(p=path)),
                              stdout=null,stderr=null)
        return proc
    
    def shutdown_server(sel):
        sel.shut_down_selenium_server()
    
    def start_selenium(host="localhost",
                       port=4444,
                       browserStartCommand="*firefox",
                       browserURL="http://www.google.com/webhp"):
        sel=selenium.selenium(host,port,browserStartCommand,browserURL)
        try:
            sel.start()
        except socket.error as err:
            proc=start_server()
            time.sleep(1)
            try:
                sel.start()
            except socket.error as err:
                sys.exit(err)
        return sel
    
    if __name__=='__main__':
        sel=start_selenium()
        time.sleep(1)
        sel.stop()
        shutdown_server(sel)    
    

