与硒

7

我是Selenium的新手,并试图通过硒驱动程序从Chrome打开本地主机:3000页。 的代码是:与硒

import com.google.common.base.Function; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebDriverException; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
public class SeleniumTests { 

    public static void main(String[] args) { 


     System.setProperty("webdriver.chrome.driver", "C://chromedriver_win32//chromedriver.exe"); 
     WebDriver driver = new ChromeDriver();    
     driver.get("localhost:3000"); 
    } 

} 

然而,这打开我的Chrome窗口, “数据”; 。 镀铬版本是50.0.2661.94

任何想法什么是确切的问题?

+0

如果您手动粘贴chrome localhost:3000,它会返回什么? – noor

回答

5

指定您正在使用的协议,而不是localhost:3000,请使用http://localhost:3000。如果这没有帮助,请参阅Chromium问题跟踪器上的评论here

0

是的,它会从数据开始。数据刚刚尝试给出URL后,'data :,'URL就是chromedriver在启动chrome时导航到的默认地址。所以这本身并不一定意味着任何事情都会出错。

import com.google.common.base.Function; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebDriverException; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
public class SeleniumTests { 

public static void main(String[] args) { 


    System.setProperty("webdriver.chrome.driver", "C://chromedriver_win32//chromedriver.exe"); 
    WebDriver driver = new ChromeDriver();    
    driver.get("https://www.google.co.in/?gfe_rd=cr&ei=KxAzV8-KEJPT8gfT0IWYAw"); 
} 

} 

它会成功打开。如果您有任何查询,请回复。快乐学习.. :-)

0

我在类似的情况已经运行,在我的情况下,修复是简单地升级铬的webdriver其最新版本(在我的情况V2.27)。

展示,而不是真正的应用程序URL Data;的原因是:

WebDriver driver = new RemoteWebDriver(new URL("http://<host>:<port>/wd/hub"), desiredCapabilities); 

未能获得创建。相反,driver对象的值为null

所以在驱动程序升级后,它已被正确创建并解决了问题。

希望这有助于谁仍然卡住!

2

确保您使用的是latest release of ChromeDriver(截至目前为2.28)。我有与data:,相同的问题。错误我已经下载旧版本,并得到指定的网址没有打开的问题,只是data:,

1

我也遇到同样的问题。我更新了chrome驱动程序并解决了问题

+0

你至少可以指出你更新的版本,所以任何对此感兴趣的人都可以比较。 – mkl

+0

我使用支持Chrome版本55-57的Chrome驱动程序2.28。下载Chrome驱动程序的链接是https://sites.google.com/a/chromium.org/chromedriver/downloads –