0

I am trying to run a webpage remotely using Selenium and then trigger a button click on it. I am able to successfully open Firefox, but the webpage is not loading, and Firefox closes automatically after sometime. (Tried google.com and other pages just as test, that too not loading). Can anyone suggest what to do here ?

OS - Ubuntu 14.04.1

Python - 2.7.6

Selenium - 3.3.0

Firefox - 39.0.3

Here is my python code

import urllib, urllib2, cookielib
from contextlib import closing
from selenium import webdriver
from selenium.webdriver import Firefox # pip install selenium
from selenium.webdriver.support.ui import WebDriverWait

with closing(Firefox(executable_path="/usr/bin/firefox")) as driver:
    driver.implicitly_wait(10)
    driver.get("https://www.google.com")
    #driver.get("http://wsb.com/Assingment2/expcase16.php")
    button = driver.find_element_by_id('send')
    button.click()
    target_window = driver.window_handles[1]
    driver.switch_to_window(target_window)
    exploit_page_content = driver.page_source
    print "Exploit successful \n" + exploit_page_content
Rangarajan K
  • 93
  • 3
  • 14

2 Answers2

4

I suspect selenium is trying to use geckodriver, since that's the default. But it's only supported from version 48 of Firefox. See Jim's answer to a different question for more info. Try using the legacy Firefox driver, like so:

driver = Firefox(executable_path="/usr/bin/firefox", capabilities= {"marionette": False })
Community
  • 1
  • 1
Mark Lapierre
  • 1,067
  • 9
  • 15
  • thanks a lot upgrading to latest Firefox solved the issue, your suggestion also worked for old Firefox version. – Rangarajan K Mar 13 '17 at 07:07
  • That's great. I added a link to an answer to a different question that gives some more info about driver compatibility with different versions of Firefox, if you or anyone else are interested. – Mark Lapierre Mar 13 '17 at 20:00
0

It seems that you're using conextlib.closing() and as per the documentation, you're basically calling the close() method on your object:

from contextlib import contextmanager

@contextmanager
def closing(thing):
    try:
        yield thing
    finally:
        thing.close()

And as per selenium documentation:

driver.close() – It closes the the browser window on which the focus is set.

As far as suggestions, it depends on what you want to do. If you want to continue processing the web page, then obviously extend your code. Or remove the context and call driver.close() explicitly when you are done. Again, it depends on what your task is.

Carlos
  • 1,897
  • 3
  • 19
  • 37
  • Hello sir, thanks for your reply. I tried removing the closing() and added driver.close() explicitly at the end. Still I am facing the same issue. `driver = Firefox(executable_path="/usr/bin/firefox") driver.implicitly_wait(3) driver.get("https://www.google.com") driver.close()` – Rangarajan K Mar 12 '17 at 16:02
  • I guess you can set page load timeouts as well: https://stackoverflow.com/questions/32276654/setting-page-load-timeout-in-selenium-python-binding – Carlos Mar 12 '17 at 16:06