0
你好下面是代码,硒司机值返回为NULL的网站
问题: 下Acti_01Login页面司机值retunring驾驶空值,因此它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();
}
}
请求你帮助我。
我的错误: Acti_03ActionOpenBrowser.setup();错误我已经使用 Acti_03ActionOpenBrowser.openBrowser(“Mozilla”); 和同我从 公共类Acti_03ActionOpenBrowser 公共静态的webdriver openBrowser(字符串sBrowserName)调用抛出异常 \t { \t \t \t \t如果(sBrowserName.equalsIgnoreCase( “Mozilla的”)) \t { \t \t \t driver = new FirefoxDriver(); \t \t \t driver.get(Constant.URL); \t \t driver.manage()。timeouts()。implicitlyWait(40,TimeUnit.SECONDS); \t \t} \t} – viki
使用此驱动程序= Acti_03ActionOpenBrowser.openBrowser(“Mozilla”);并通过此驱动程序下面的所有方法,你不会得到零点异常 –
谢谢它正在工作,请让我知道背后的原因是什么。 如果你能为我提供链接,这将是很好的。 – viki