硒中的Java nullpoint错误



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

是什么
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");

ou并无法获得该特定配置文件。尝试检查您的个人资料并在此处进行更改。您的设置也是错误的。更改您的第一行:

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

这是您需要地址的一些关键点:

  1. System.SetProperty-您需要正确提及webdriver.gecko.driver
  2. FirefoxProfile testprofile = profile.getProfile("default"):值得一提的是,默认的firefox配置文件不是很友好。当您想在Firefox浏览器上可靠地运行自动化时,建议您进行单独的配置文件。自动化配置文件应轻巧,并具有特殊的代理和其他设置以进行良好的测试。您应该与所有开发和测试执行机上使用的配置文件一致。如果您到处使用了不同的配置文件,则您接受的SSL证书或安装的插件将有所不同,这会使测试在机器上的行为不同。

    • 有几次您需要在个人资料中进行特殊的内容,以使测试执行可靠。最常见的示例是处理自签名证书的SSL证书设置或浏览器插件。创建一个满足这些特殊测试需求的配置文件并将其与测试执行代码一起部署很有意义。
    • 您应该使用非常轻巧的配置文件,只需使用您需要的设置和插件才能执行。每次Selenium启动一个新的会话驱动Firefox实例时,都会在某个临时目录中复制整个配置文件,如果配置文件很大,它使它不仅慢,而且也不可靠。
    • 创建一个新的Firefox配置文件,并在测试脚本中使用相同的内容涉及三个步骤过程。首先,您需要启动配置文件管理器,其次是创建一个新的配置文件,第三个是在测试脚本中使用相同的配置文件。假设我们用名称" Debanjan"创建了一个新的Firefoxprofile。
  3. 使用以下代码使用您的新FirefoxProfile" Debanjan"打开https://www.w3schools.com/

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

最新更新