0

I try to call firefox via selenium in Python on an AWS machine.

I check the previous posts (this one and this one). However, their solutions do not directly work for me. I used the following code samples, but had the errors as mentioned below.

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(1024, 768))
display.start()

driver= webdriver.Firefox()
driver.get("http://www.somewebsite.com/")

<---some code--->

#driver.close() # Close the current window.
driver.quit() # Quit the driver and close every associated window.
display.stop()

I got the following error:

> driver= webdriver.Firefox()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 81, in __init__
    self.binary, timeout)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 51, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 98, in _wait_until_connectable
    raise WebDriverException("The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. 
If you specified a log_file in the FirefoxBinary constructor, check it for details.

I installed xvfb and pyvirtualdisplay without error. My firefox is up-to-date.

If I run firefox alone, I also got some error as follows.

> firefox &
[2] 1436
> PuTTY X11 proxy: unable to connect to forwarded X server: Network error: Connection refused
[2]-  Exit 127

Please feel free to share your thoughts. Thanks!

Community
  • 1
  • 1
Neverfaraway
  • 57
  • 3
  • 10

0 Answers0