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

时间:2016-01-13 15:34:10

标签: java selenium selenium-webdriver

嗨以下是代码,

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

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


    }

}

请你帮助我。

1 个答案:

答案 0 :(得分:-1)

我无法查看安装方法的代码,但调用

  Acti_03ActionOpenBrowser.setup();

我希望你需要在POMtest1中使用下面的一个而不是一个

  driver=Acti_03ActionOpenBrowser.openBrowser("Mozilla");

很高兴使用公共静态WebDriver驱动程序。

谢谢你, 穆拉利

相关问题