Rangarajan K
Rangarajan K

Reputation: 83

Webpage not opening in Firefox - Selenium Python

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

Upvotes: 0

Views: 2300

Answers (2)

Mark Lapierre
Mark Lapierre

Reputation: 1087

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 })

Upvotes: 4

Carlos
Carlos

Reputation: 1925

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.

Upvotes: 0

Related Questions