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
1
  • Do you see any error messages on your console? Commented Mar 12, 2017 at 22:51

2 Answers 2

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 })
Sign up to request clarification or add additional context in comments.

2 Comments

thanks a lot upgrading to latest Firefox solved the issue, your suggestion also worked for old Firefox version.
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.
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.

2 Comments

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()
I guess you can set page load timeouts as well: stackoverflow.com/questions/32276654/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.