Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
selenium中的Java空点错误_Java_Selenium_Selenium Webdriver - Fatal编程技术网

selenium中的Java空点错误

selenium中的Java空点错误,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,下面是我的代码,但它给了我空点错误。请帮我找出一些错误 package path1; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.firefox.internal.ProfilesIni; public cl

下面是我的代码,但它给了我空点错误。请帮我找出一些错误

package path1;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;

public class New1 {
  public static void main(String[] args) {          
    System.setProperty("webdriv`enter code here`er.gecko.driver", "C://Users/Ramesh/Desktop/Udemy/Selenium/geckodriver.exe");      
    ProfilesIni profile = new ProfilesIni();

    FirefoxProfile testprofile = profile.getProfile("default");
    testprofile.setAcceptUntrustedCertificates(true);
    testprofile.setAssumeUntrustedCertificateIssuer(true);

    WebDriver driver = new FirefoxDriver(testprofile);
    driver.get("https://www.w3schools.com/");
  }    
}

因为这一行:

     FirefoxProfile testprofile = profile.getProfile("default");
Ý你无法获得具体的个人资料。尝试检查您的个人资料并在那里进行更改。此外,您的设置是错误的。用以下命令更改第一行:

 System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");

以下是您需要解决的一些关键问题:

System.setProperty-您需要正确地提及webdriver.gecko.driver FirefoxProfile testprofile=profile.getProfiledefault:值得一提的是,默认的Firefox配置文件对自动化不太友好。当您希望在Firefox浏览器上可靠地运行自动化时,建议创建一个单独的配置文件。自动化配置文件应轻载,并具有特殊的代理和其他设置,以运行良好的测试。您应该与在所有开发和测试执行机器上使用的配置文件保持一致。如果您在任何地方都使用不同的配置文件,那么您接受的SSL证书或安装的插件将不同,这将使测试在机器上的行为不同

有时,您需要在概要文件中添加一些特殊的内容,以确保测试执行的可靠性。最常见的示例是处理自签名证书的SSL证书设置或浏览器插件。创建一个处理这些特殊测试需求的概要文件,并将其与测试执行代码一起打包和部署,这非常有意义。 您应该使用一个非常轻量级的概要文件,其中只包含执行所需的设置和插件。每次Selenium启动驱动Firefox实例的新会话时,它都会将整个配置文件复制到某个临时目录中,如果配置文件很大,它不仅速度慢而且不可靠。 创建一个新的Firefox配置文件并在测试脚本中使用该配置文件包括三个步骤。首先需要启动概要文件管理器,第二个是创建新概要文件,第三个是在测试脚本中使用相同的概要文件。假设我们创建了一个名为debanjan的新FirefoxProfile。 使用以下代码打开https://www.w3schools.com/ 使用新的FirefoxProfile debanjan:

System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("debanjan");
testprofile.setAcceptUntrustedCertificates(true);
testprofile.setAssumeUntrustedCertificateIssuer(true);
WebDriver driver = new FirefoxDriver(testprofile);
driver.get("https://www.w3schools.com/");

你调试代码了吗?没有“空点错误”或“空点错误”之类的东西。你得到的是一个NullPointerException。准确点。@EJPI怀疑是否有人会得到NullPointerException,但我清楚地看到了HeapException,因为我试图加载默认配置文件。