Issues in ruuing scripts for DDF 2016 | Selenium Forum
M
Posted on 03/08/2016
Hi Ashish Sir,

i am just started following DDF 2016, and completed part 3 video. in which we are Building the BaseTest and functions in base test. Whenever i am running dummytest b class with xpath locators it is working, however when I am trying to run with ID and Name locator , facing No Such element exception and unreachable code respectively. Please look into my code and help me to understand where is the error.

[b:1hvv7hih]Here the current code of Dummy class:[/b:1hvv7hih]

package CoreDDF.testcases;


import org.testng.annotations.Test;
import DDF.BaseTest;

public class dummyclassB extends BaseTest {

@Test
public void dummyTestB() {

openbrowser("Mozilla");
navigate("appurl");
type("email_name", "anshuman.saini1987@gmail.com");
click("button_xpath");
//verifydata();
// ReportFail("Meesage is not correct");

[b:1hvv7hih]Code of Base Class[/b:1hvv7hih]

package DDF;

import java.io.FileInputStream;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;

public class BaseTest {

public WebDriver driver;
public Properties prop;



public void openbrowser(String bType){

//intializing prop variable
if(prop == null){
prop = new Properties();

try{
FileInputStream fs = new FileInputStream(System.getProperty("user.dir")+ "//src//test//resources//Projectconfig.properties");
prop.load(fs);
}catch(Exception e){
e.printStackTrace();
}
}

if(bType.equals("Mozilla"))
driver = new FirefoxDriver();
else if (bType.equals("Chrome")){
System.setProperty("Webdriver.Chrome.driver", prop.getProperty("chromedriver.exe"));
driver = new ChromeDriver();
}
else if (bType.equals("IE")){
System.setProperty("Webdriver.IE.driver", prop.getProperty("Internetexlorerdriver.exe"));
driver = new InternetExplorerDriver();
}
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();


}

public void navigate(String urlkey){
driver.get(prop.getProperty(urlkey));

}

public void click(String locatorKey){
driver.findElement(By.xpath(prop.getProperty(locatorKey))).click();
}

public void type(String locatorKey,String keys){
driver.findElement(By.xpath(prop.getProperty(locatorKey))).sendKeys(keys);
}

public WebElement getElement(String locatorKey){
WebElement e=null;
try{
if(locatorKey.endsWith("_id"))
e = driver.findElement(By.id(prop.getProperty(locatorKey)));
else if(locatorKey.endsWith("_name"))
e = driver.findElement(By.name(prop.getProperty(locatorKey)));
else if(locatorKey.endsWith("_xpath"))
e = driver.findElement(By.xpath(prop.getProperty(locatorKey)));
else{
ReportFail("Locator not correct - " + locatorKey);
Assert.fail("Locator not correct - " + locatorKey);
}

}catch(Exception ex){
// fail the test and report the error
ReportFail(ex.getMessage());
ex.printStackTrace();
Assert.fail("Failed the test - "+ex.getMessage());
}
return e;
}


/******************************* validation****************************/

public boolean verifydata(){
return false;

}

public boolean IsElementPresent(){
return false;
}

public boolean Text(){
return false;
}

/**********************Reporting*****************/

public void ReportPass(String Message){

}

public void ReportFail(String Message){

}

public void TkeScreenShot(){

}
}


Code of property file :

appurl = https://accounts.google.com
ChromeDriver = E:\\chromedriver.exe
IEDriver = E:\\Internetexlorerdriver.exe

#Locators
appurl = https://accounts.google.com
email_xpath = //*[@id='Email']
email_id =Email
email_name=Email
button_xpath = //*[@id='next']

[b:1hvv7hih]Error message when using Name : [/b:1hvv7hih]

FAILED: dummyTestB

org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'Kaku-PC', ip: '192.168.1.6', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91'
Driver info: driver.version: RemoteWebDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=33.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: ce4b1967-5df1-4dfa-b6fd-2ea4c9166932

Error message with ID :

FAILED: dummyTestB
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"Email"}
Command duration or timeout: 30.01 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'Kaku-PC', ip: '192.168.1.6', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=33.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 07913333-080a-4299-b914-ee17b3611dc7
*** Element info: {Using=xpath, value=Email}

M
Replied on 03/08/2016

send a screen shot.


M
Replied on 03/08/2016

Screen shot of error or cods or both ?


M
Replied on 04/08/2016

of exception.


M
Replied on 04/08/2016

Hi ,

PFA of exceptions

Responsive image

M
Replied on 04/08/2016

first screen shot with ID locator and second one for Name locator. Please help me thanks in advance.


M
Replied on 05/08/2016

your xpath is wrong.

dummytestB line 35. please check the xpath.