35
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?

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
BrickByBrick
  • 1,211
  • 2
  • 10
  • 12
  • 3
    Did you fix this issue ? I meet the same problem on my ubuntu. – WoooHaaaa Sep 21 '12 at 06:26
  • Try to use https://github.com/iamalittletester/thewaiter. This can be helpfull. See here howto: https://imalittletester.com/2018/04/10/thewaiter-opening-a-page-and-waiting-for-it-to-load-with-selenium/ – gandra404 Sep 26 '18 at 14:36

19 Answers19

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
grdshch
  • 341
  • 2
  • 4
  • 2
    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? – Blink Aug 06 '15 at 16:35
  • Didn't help to me, MAC – kashesandr Aug 27 '15 at 14:47
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

R1ky68
  • 40
  • 1
  • 8
Goutham
  • 109
  • 1
  • 4
  • 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 – AdjunctProfessorFalcon Jul 10 '15 at 20:19
  • 1
    or upgrade mozilla :) – CKM Nov 14 '17 at 10:16
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:

jwpfox
  • 5,124
  • 11
  • 45
  • 42
Amit
  • 178
  • 1
  • 6
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.

WoooHaaaa
  • 19,732
  • 32
  • 90
  • 138
  • 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. – Jake Johnson May 07 '15 at 19:19
  • 1
    You should never use 777 permissions. It's very dangerous. – user3735633 May 29 '15 at 16:09
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")));
sachin2013
  • 11
  • 1
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.

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.

kashesandr
  • 1,521
  • 28
  • 35
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.

Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
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);
    }

}
HK boy
  • 1,398
  • 11
  • 17
  • 25
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()
Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145
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.

Praneeth T T
  • 305
  • 3
  • 9
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.

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

fanbyprinciple
  • 554
  • 7
  • 14
-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.

Layla
  • 347
  • 1
  • 6
  • 13
-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")
-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

Community
  • 1
  • 1
amitdatta
  • 760
  • 6
  • 14
-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.

Thomas
  • 34
  • 4
  • 2
    I tried this too. I am at a loss. It just does not open any url. – Neeraj Nov 08 '11 at 10:27
  • Maybe you have a typo? In your question you are writing: "driver.get("http:...")", but it must be "driver.getURL("http:...") – Thomas Nov 17 '11 at 13:49
-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");
A. Luiten
  • 5
  • 2
-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);
Curious
  • 282
  • 4
  • 21