I am constantly running into this error on execution of Scripts with Cucumber framework. The browser is launched successfully with the given URL.It validates the presence of element after Login as well. But when I try to click on that element it fails and give the below error.
I have tired to execute the code with below Approaches as well : 1. Using TestNG 2. As Java Application
public class POMTestRunner {
public static WebDriver driver;
public static WebDriverWait wait;
@BeforeSuite
public void initializeTest() {
System.setProperty("webdriver.chrome.driver", UtilityClass.ChromeDriverpath);
ChromeOptions Options = new ChromeOptions();
Options.addArguments("start-maximized");
Options.addArguments("disable-notifications");
Options.setPageLoadStrategy(PageLoadStrategy.NORMAL);
driver = new ChromeDriver(Options);
wait = new WebDriverWait(driver,60);
driver.get(UtilityClass.AppURL);
}
@Test
public void RequirementOne() throws Exception {
PageMethods ReqOne = new PageMethods(driver,wait);
ReqOne.SalesForceLogin();
ReqOne.waitForJQueryToBeActive();
ReqOne.NewOpportunityCreation();
ReqOne.ValidateDealSize();
}
@AfterSuite
public void endTest() {
driver.quit();
driver=null;
}
PageMethodClass :
public class PageMethods extends PageObjectsClass {
public WebDriver driver;
public WebDriverWait wait;
public PageMethods(WebDriver driver, WebDriverWait wait) {
this.driver=driver;
this.wait=wait;
}
public void waitForJQueryToBeActive() {
Boolean isJqueryUsed = (Boolean) ((JavascriptExecutor) driver)
.executeScript("return (typeof(jQuery) != 'undefined')");
if (isJqueryUsed) {
while (true) {
// JavaScript test to verify jQuery is active or not
Boolean ajaxIsComplete = (Boolean) (((JavascriptExecutor) driver)
.executeScript("return jQuery.active == 0"));
if (ajaxIsComplete)
break;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
}
}
public void SalesForceLogin() {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username"))).sendKeys(UtilityClass.Username);
driver.findElement(By.id("password")).sendKeys(UtilityClass.Password);
driver.findElement(By.id("Login")).click();
String OpportunityTab = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[text()='Opportunities']"))).getText();
if(OpportunityTab.contains("Opportunities")) {
System.out.println("Login Successful");
}else {
System.out.println("Login Failed. Abort Execution");
}
}
public void NewOpportunityCreation() throws InterruptedException {
Thread.sleep(5000);
wait.until(ExpectedConditions.visibilityOfElementLocated(OpportunitiesTab)).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(NewOpportunityButton)).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(OpportunityName)).sendKeys("AutomationFrameworkOpportunity");
driver.findElement(OpportunityAmount).sendKeys(UtilityClass.Amount);
driver.findElement(OpportunityCloseDateCalendar).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(OpportunityCloseDate)).click();
driver.findElement(Stage).click();
driver.findElement(OpportunityStageQualification).click();
driver.findElement(SaveButton).click();
}
public void ValidateDealSize() {
wait.until(ExpectedConditions.visibilityOfElementLocated(OpportunityDetailsTab)).click();
String DealSize = wait.until(ExpectedConditions.visibilityOfElementLocated(DealSizeValue)).getText();
Integer AmountValue = Integer.parseInt(UtilityClass.Amount);
if(AmountValue<1000) {
Assert.assertEquals(DealSize, "");
}
else if(AmountValue>50000) {
Assert.assertEquals(DealSize, "Big Deal");
}
else if(AmountValue>1000 && AmountValue<=9999) {
Assert.assertEquals(DealSize, "Small");
}
else if(AmountValue>10000 && AmountValue<=50000) {
Assert.assertEquals(DealSize, "Medium");
}
else {
System.out.println("Entered Opportunity Amount Does not match any criteria. Deal Size not validated.");
}
}
}
Tried to find the answers through the existing questions on forum but couldn't find the solution to the problem. Would also like to know the meaning of this error on what it exactly means.
Error Stack Trace :
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'defaultView' of undefined
(Session info: chrome=73.0.3683.103)
(Driver info: chromedriver=72.0.3626.69 (3c16f8a135abc0d4da2dff33804db79b849a7c38),platform=Windows NT 10.0.17763 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'PDC2LAP-7173253', ip: '10.170.9.243', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 72.0.3626.69 (3c16f8a135abc..., userDataDir: C:\Users\KOVIDA~1.MEH\AppDa...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:60915}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 73.0.3683.103, webStorageEnabled: true}
Session ID: 957f6f09e6c094d82a7addda8a37ee66
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at stepDefinitionTOD.PageMethods.NewOpportunityCreation(PageMethods.java:36)
at testrunnerTOD.POMTestRunner.main(POMTestRunner.java:53)
Not a duplicate to : An error has occured in 'site url': Uncaught TypeError: Cannot read property 'getColomnSet' of undefined with Selenium and Python
I have used Explicit wait and Thread.Sleep to ensure the DOM loads completely before the interactions. Page Load Strategy has been used as well.
Used the approaches mentioned in previously answered question as below : 1. Added chromedriverOptions for page load strategy : Options.setPageLoadStrategy(PageLoadStrategy.NORMAL); 2. Added WaitForAjax2Complete before the method where I was getting the error. 3. Used WebDriverWait to locate and click on the element.
Please answer if there are any other approach for this.