36
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
import time


# Create a new instance of the Firefox driver
driver = webdriver.Firefox()


# go to the google home page
driver.get("http://www.google.com")

This opens a Firefox window but does not open a url.

  1. I have a proxy server(but the address bar does not show the passed url)
  2. I have two Firefox profiles.

Can 1 or 2 be an issue? if yes, then how can I resolve it?

2

19 Answers 19

16

It is a defect of Selenium.
I have the same problem in Ubuntu 12.04 behind the proxy.

Problem is in incorrect processing proxy exclusions. Default Ubuntu exclusions are located in no_proxy environment variable:

no_proxy=localhost,127.0.0.0/8

But it seems that /8 mask doesn't work for selenium. To workaround the problem it is enough to change no_proxy to the following:

no_proxy=localhost,127.0.0.1

Removing proxy settings before running python script also helps:

http_proxy= python script.py
Sign up to request clarification or add additional context in comments.

2 Comments

Can you give a little more information on how you set no_proxy? You called it an environment variable, but I tried setting it export no_proxy=localhost,127.0.0.1 and that does nothing. And I misinterpreting your instructions?
Didn't help to me, MAC
10

I was facing exactly the same issue, after browsing for sometime,I came to know that it is basically version compatibility issue between FireFox and selenium. I have got the latest FireFox but my Selenium imported was older which is causing the issue. Issue got resolved after upgrading selenium

pip install -U selenium

OS: windows Python 2.7

2 Comments

Would you mind sharing your method for retrieving current URL in open browser? I'm trying to grab redirect URL, but using print driver.current_url only prints the original URL that was passed when I first opened the browser
or upgrade mozilla :)
2

I have resolved this issue.

If your jar files are older than the latest version and the browser has updated to latest version, then download:

1 Comment

I tried this and upgraded to Selenium 3.0.1, but still same issue.
1

@Neeraj

I've resolved this problem, but i'm not sure if you are the same reason.

In general, my problem was caused by some permission issues.

I tried to move my whole project into ~/:

mv xxx/ ~/

and then i change give it the 777 permission:

chmod -R 777 xxx/

I'm not familiar with linux permission so i just do this to make sure i have permission to execute the program.

Even you don't have permission, the selenium program will not prompt you.

So, good luck.

2 Comments

This didn't exactly solve the problem for me, but it did get me on the right track. When I installed the selenium-webdriver gem i used sudo gem install selenium-webdriver. I then reinstalled it without using sudo and it fixed my problem. It is true that selenium will fail silently if there is a permission issue.
You should never use 777 permissions. It's very dangerous.
1
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
driver.get("http://www.google.com");

OR

import org.openqa.selenium.support.ui.ExpectedConditions;

WebDriverWait wait = new WebDriverWait(driver,30);
driver.get("http://www.google.com");
//hplogo is the id of Google logo on google.com
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("hplogo")));

Comments

1

I had the similar problem. All I had to do was delete the existing geckodriver.exe and download the latest release of the same. You can find the latest release here https://github.com/mozilla/geckodriver/releases.

Comments

0

A spent a lot of time on this issue and finally found that selenium 2.44 not working with node version 0.12. Use node version 0.10.38.

Comments

0

I got the same error when issuing a URL without the protocol (like localhost:4200) instead of a correct one also specifying the protocol (e.g. http://localhost:4200).

Google Chrome works fine without the protocol (it takes http as the default), but Firefox crashes with this error.

Comments

0

I was getting similar problem and Stating string for URL worked for me. :)

package Chrome_Example;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Launch_Chrome {

    public static void main(String[] args) {

        System.setProperty("webdriver.chrome.driver", "C:\\Users\\doyes\\Downloads\\chromedriver_win324\\chromedriver.exe");
        String URL = "http://www.google.com";
        WebDriver driver = new ChromeDriver();
        driver.get(URL);
    }

}

1 Comment

I tried but not working
0

I had the same problem but with Chrome.

Solved it using the following steps

  1. Install Firefox/Chrome webdriver from Google
  2. Put the webdriver in Chrome's directory.

Here's the code and it worked fine

from selenium import webdriver

class InstaBot(object):
    def __init__(self):
        self.driver=webdriver.Chrome("C:\Program 
        Files(x86)\Google\Chrome\Application\chromedriver.exe")# make sure 
                                                      #it is chrome driver 
        self.driver.get("https://www.wikipedia.com")
        
        
InstaBot()

Comments

0

Check your browser version and do the following.

1. Download the Firefox/Chrome webdriver from Google

2. Put the webdriver in Chrome's directory.

Comments

0

I was having the save issue when trying with Chrome. I finally placed my chromedrivers.exe in the same location as my project. This fixed it for me.

Comments

0

Update your driver based on your browser.

In my case for chrome,

  1. Download latest driver for your chrome from here : https://chromedriver.chromium.org/downloads Check chrome version from your browser at : chrome://settings/help.

  2. While initialising your driver, use driver = webdriver.Chrome(executable_path="path/to/downloaded/driver")

Comments

-1

Please have a look at this HowTo: http://www.qaautomation.net/?p=373 Have a close look at section "Instantiating WebDriver"

I think you are missing the following code line:

wait = new WebDriverWait(driver, 30);

Put it between

driver = webdriver.Firefox();

and

driver.getUrl("http://www.google.com");

Haven't tested it, because I'm not using Selenium at the moment. I'm familiar with Selenium 1.x.

2 Comments

I tried this too. I am at a loss. It just does not open any url.
Maybe you have a typo? In your question you are writing: "driver.get("http:...")", but it must be "driver.getURL("http:...")
-1

I was having the save issue. I assume you made sure your java server was running before you started your python script? The java server can be downloaded from selenium's download list.

When I did a netstat to evaluate the open ports, i noticed that the java server wasn't running on the specific "localhost" host:

When I started the server, I found that the port number was 4444 :

$ java -jar selenium-server-standalone-2.35.0.jar 
Sep 24, 2013 10:18:57 PM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
22:19:03.393 INFO - Java: Apple Inc. 20.51-b01-456
22:19:03.394 INFO - OS: Mac OS X 10.8.5 x86_64
22:19:03.418 INFO - v2.35.0, with Core v2.35.0. Built from revision c916b9d
22:19:03.681 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
22:19:03.683 INFO - Version Jetty/5.1.x
22:19:03.683 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
22:19:03.685 INFO - Started HttpContext[/selenium-server,/selenium-server]
22:19:03.685 INFO - Started HttpContext[/,/]
22:19:03.755 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@21b64e6a
22:19:03.755 INFO - Started HttpContext[/wd,/wd]
22:19:03.765 INFO - Started SocketListener on 0.0.0.0:4444

I was able to view my listening ports and their port numbers(the -n option) by running the following command in the terminal:

$netstat -an | egrep 'Proto|LISTEN'

This got me the following output

Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)    

tcp46      0      0  *.4444                 *.*                    LISTEN  

I realized this may be a problem, because selenium's socket utils, found in: webdriver/common/utils.py are trying to connect via "localhost" or 127.0.0.1:

socket_.connect(("localhost", port))

once I changed the "localhost" to '' (empty single quotes to represent all local addresses), it started working. So now, the previous line from utils.py looks like this:

socket_.connect(('', port))

I am using MacOs and Firefox 22. The latest version of Firefox at the time of this post is 24, but I heard there are some security issues with the version that may block some of selenium's functionality (I have not verified this). Regardless, for this reason, I am using the older version of Firefox.

Comments

-1

This worked for me (Tested on Ubuntu Desktop 11.04 with Python-2.7):

from selenium import webdriver

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

Comments

-1

Since you mentioned you use a proxy, try setting up the firefox driver with a proxy by following the answer given here proxy selenium python firefox

Comments

-2

Try the following code

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

WebDriver DRIVER = new FirefoxDriver();
DRIVER.get("http://www.google.com");

Comments

-6

You need to first declare url as a sting as below:

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
import time


# Create a new instance of the Firefox driver

String URL = "http://www.google.com";

driver = webdriver.Firefox()


# go to the google home page
driver.get(URL);

1 Comment

It's not a big deal. Besides, It doesn't help, at least in the case. -1 for that

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.