Selenium WebDriver.get(url) does not open the URL

前端 未结 18 2010
醉梦人生
醉梦人生 2020-11-29 07:36
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui impo         


        
18条回答
  •  佛祖请我去吃肉
    2020-11-29 07:58

    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.

提交回复
热议问题