java.lang.NullPointerException:条目中的null值:url = null Selenium Webdriver

时间:2015-08-04 16:58:32

标签: selenium-webdriver nullpointerexception selenium-chromedriver

我正在尝试以下简单代码,它按照我的localmachine

的预期工作
public class NewTest 
{

  @Test
  public void f() throws IOException
  {   

  Properties obj = new Properties();
  FileInputStream fileobj = new FileInputStream("C:\\selenium_Automation\\data_links.properties");
  obj.load(fileobj);

  System.setProperty("webdriver.chrome.driver", "c:\\drivers\\chromedriver.exe");
  WebDriver driver = new ChromeDriver();
  driver.get(obj.getProperty("crm_url"));

  System.out.println("Complete");
  }

}

但是当我在不同的机器上尝试相同的代码时,我得到以下内容

 FAILED: f
 java.lang.NullPointerException: null value in entry: url=null
at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:33)
at com.google.common.collect.SingletonImmutableBiMap.<init>(SingletonImmutableBiMap.java:39)
at com.google.common.collect.ImmutableBiMap.of(ImmutableBiMap.java:57)
at com.google.common.collect.ImmutableMap.of(ImmutableMap.java:80)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:306)

如果我用实际的URL替换(obj.getProperty(“crm_url”)),代码工作正常,但是我在属性文件中存储了几个不同的链接,我需要从那个地方读取它们。 我做错了可以请一些人告诉我NUll指针预测URL的原因

4 个答案:

答案 0 :(得分:2)

当您尝试将null对象添加到Google公共库中的不可变地图时,会出现此错误。我的猜测是org.openqa.selenium.remote.RemoteWebDriver.get试图找到这样做,你的文件路径是null或类似的东西。我会检查网址,但这只是猜测。

答案 1 :(得分:1)

如果我不得不猜测,我会说你的属性文件的位置在另一台机器上是不同的。

答案 2 :(得分:0)

我可以假设的问题是,您在属性文件中使用的url必须是错误的,否则可能会有逗号颠倒的情况。如果它有逗号倒置,即 url =“ https://www.google.com”,然后将其删除。

答案 3 :(得分:-1)

即使我遇到过这个问题。在运行代码之前,我删除了目标文件夹,问题已解决。