0

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.

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
Kovid Mehta
  • 531
  • 2
  • 8
  • 28
  • Hi @debanjan This is not a duplicate to that Question. I have added the PageLoadStrategy as well and using explicit wait as well to interact with the elements but it doesn't work. – Kovid Mehta Apr 15 '19 at 09:57
  • Have you gone through the dup target properly once? _...Cannot read property..._ is a typical scenario when the JS haven't completed loading the DOM and _PageLoadStrategy_ is one of the approaches. See: [Do we have any generic funtion to check if page has completely loaded in Selenium](https://stackoverflow.com/questions/50327132/do-we-have-any-generic-funtion-to-check-if-page-has-completely-loaded-in-seleniu/50329056#50329056) – undetected Selenium Apr 15 '19 at 10:12
  • Yes I have read that. There are three approaches mentioned : 1. PageLoadStrategy 2. wait for Ajax to complete 3. WebDriverWait. I have used all the three approaches mentioned but still running into the same error. – Kovid Mehta Apr 15 '19 at 10:16
  • I can still see you using `chromedriver=72.0.3626.69` for `chrome=73.0.3683.103`. Have you got a chance to see the [ChromeDriver - WebDriver for Chrome](https://sites.google.com/a/chromium.org/chromedriver/downloads) – undetected Selenium Apr 15 '19 at 10:32
  • Yes I just changed it to Chrome=73 as well. Still doesn't work. – Kovid Mehta Apr 15 '19 at 10:37
  • You already had **Chrome=73**, rather you should have updated to **chromedriver=73.0**. See the explaination at [org.apache.commons.exec.ExecuteException: Process exited with an error with ChromeDriver Chrome Selenium and TestNG Suite](https://stackoverflow.com/questions/54928528/org-apache-commons-exec-executeexception-process-exited-with-an-error-with-chro) – undetected Selenium Apr 15 '19 at 10:46
  • Hey Debanjan, Sorry for the confusion. I meant to say I have updated the ChromeDriver to 73 to match Chrome73. – Kovid Mehta Apr 15 '19 at 10:49
  • Please update the question with your current code trial including 1. PageLoadStrategy 2. wait for Ajax to complete 3. WebDriverWait along with 4. Chrome/ChromeDriver and the error trace logs for further analysis. – undetected Selenium Apr 15 '19 at 10:54
  • Updated the Current Trial Code. Solved it temporarily with the help of Javascriptexecutor. – Kovid Mehta Apr 16 '19 at 09:38
  • 1
    Of coarse `Javascriptexecutor` is a way but should be last resort. Perhaps proper usage of _WebDriverWait_ would have solve your issues in the best possible way. – undetected Selenium Apr 16 '19 at 09:44

0 Answers0