Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.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
Java 网站的selenium驱动程序值返回为NULL_Java_Selenium_Selenium Webdriver - Fatal编程技术网

Java 网站的selenium驱动程序值返回为NULL

Java 网站的selenium驱动程序值返回为NULL,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,下面是代码 问题: Acti_01Login页面下的驱动程序值将驱动程序值返回为NULL,因此它是Throwing异常。如何处理并确保其不返回空值 ////////////////////////////Page Object Model: public class Acti_01LoginPage { private static WebElement element = null; static WebDriverWait wait; //Username Tex

下面是代码

问题: Acti_01Login页面下的驱动程序值将驱动程序值返回为NULL,因此它是Throwing异常。如何处理并确保其不返回空值

////////////////////////////Page Object Model:
public class Acti_01LoginPage
{
    private static WebElement element = null;
    static WebDriverWait wait;


    //Username TextBox
    public static WebElement input_TxtUsername(WebDriver driver)
     {
    System.out.println("Driver in Action login page "+ driver);  
    try
    {
        element =driver.findElement(By.id("username"));
        Log.info("Username textbox element is found");
        //System.out.println(element);

    }
    catch (WebDriverException e)
    {
            //System.out.println(e.getMessage());
            Log.info("Username textbox element is not found due to "+e.getMessage());
    }
     return element;
 }

//ActionOpenBrowser
package funcModule;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import utility.Constant;

public class Acti_03ActionOpenBrowser 
{

    WebDriver driver=null;

        public  WebDriver openBrowser(String sBrowserName) throws Exception
        {


            if(sBrowserName.equalsIgnoreCase("Mozilla"))
            {

                driver = new FirefoxDriver();

                driver.get(Constant.URL);
                driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);

                }
            else if(sBrowserName.equalsIgnoreCase("chrome"))
            {

                System.setProperty("webdriver.chrome.driver","chromedriver.exe");
                driver = new ChromeDriver();
                driver.get(Constant.URL);
                driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);

            }

            return driver;
        }

}

Callin in Main function:
public class POMtest1 {

    private static WebDriver driver = null;
    public static void main(String[] args) throws Exception 
    {
        Acti_03ActionOpenBrowser.setup();

        Acti_01LoginPage.input_TxtUsername(driver).sendKeys("vjha9009");

        Acti_01LoginPage.input_TxtPassword(driver).sendKeys("Password123");
        Acti_01LoginPage.click_BtnLogin(driver).click();


    }

}

请您帮助我。

我看不到安装方法的代码,但正在调用

  Acti_03ActionOpenBrowser.setup();
我希望您需要在POMtest1中使用下面的一个,而不是上面的一个

  driver=Acti_03ActionOpenBrowser.openBrowser("Mozilla");
很好使用公共静态WebDriver

谢谢,,
Murali

我的错误:Acti_03ActionOpenBrowser.setup();错了吗?我用了Acti_03ActionOpenBrowser.openBrowser(“Mozilla”);我从公共类action openBrowser调用的同一个公共静态WebDriver openBrowser(字符串sBrowserName)抛出异常{if(sBrowserName.equalsIgnoreCase(“Mozilla”){driver=new FirefoxDriver();driver.get(Constant.URL);driver.manage().timeouts().implicitlyWait(40,TimeUnit.SECONDS);}}使用此驱动程序=Acti_03ActionOpenBrowser.openBrowser(“Mozilla”);并将此驱动程序传递给以下所有方法,您不会得到空点异常。如果它正在工作,请让我知道相同操作背后的原因。如果您能为我提供ame.method action\u 03ActionOpenBrowser.openBrowser(“Mozilla”)的链接,那就太好了;将在此处启动webdriver并返回驱动程序实例。我们需要收集相同的驱动程序,并使用另一种方法。如果没有,它将抛出null异常,因为没有驱动程序。所以使用driver=Acti_03ActionOpenBrowser.openBrowser(“Mozilla”);明白了。这个答案可以帮助用户解决问题。为什么会被否决?不知道为什么人们在没有解释问题的情况下用否决票批评