sharkondero
sharkondero

Reputation: 73

PhantomJS and Python: Kill current driver open new one error

When killing a driver with any of the following solutions borrowed from this SO question:

driver.close()

or:

driver.quit()

or both together:

driver.close()
driver.quit()

or this:

import signal

driver.service.process.send_signal(signal.SIGTERM) # kill the specific phantomjs child proc
driver.quit() 

It works and the window is closed, I checked the processes and nothing seemed to be left behind,

"phantomjs" in (p.name() for p in psutil.process_iter())

returned False, hopefully that's reliable enough to know the processes are dead. My eyes also verified it via task manager (using win 10). The problem I run into is when I try to instantiate a new driver. I start it like normal and the window opens:

driver = webdriver.PhantomJS
driver()

But as soon as I try to pass a command like so:

driver.set_window_size(1200, 1080) 

The shell returns this error:

TypeError: unbound method set_window_size() must be called with WebDriver instance as first argument (got int instance instead)

I tried multiple commands, sometimes it's "got int instance", sometimes "got str instance". Anyone have any idea what I'm doing wrong? I'm looking to either run simultaneous drivers (one with a proxy one without, can be different launchers), or kill the original and open a working original. Also tried multirunning with chrome driver which returns the same error under the same conditions.

Upvotes: 1

Views: 322

Answers (1)

sharkondero
sharkondero

Reputation: 73

Was missing a () after element initialization. If you have also wasted 7 hours of your life on this, I hope you feel some relief now that you know that the proper way to initialize a driver is driver = webdriver.PhantomJS().

Upvotes: 1

Related Questions