Unable to click 'Accounts' menu item on Saleforce Homepage

783 views
Skip to first unread message

Andrew Gibbs

unread,
Nov 11, 2019, 11:40:15 AM11/11/19
to Selenium Users
Hi All,

I'm having an issue scripting against Salesforce with Selenium.

I manage to login, but once on the homepage I'm unable to click on the 'Accounts' menu item on the horizontal menu.

First Attempt

The xpath for the Accounts menu item can be seen in the attached screenshot.

The code that was called (clickAccountMnu) to click on the Accounts menu looked like this:
package designpattern;

import base.WebBaseBDD;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import toolspecificlibrary.WebUtils;

public class SaleforceHomePage extends WebBaseBDD {
public SaleforceHomePage(WebDriver driver) {
this.webDriver = driver;
PageFactory.initElements(driver, this);
}

/**
* Locators for the Home Page are defined in this class
*/

@FindBy(xpath = "//span[@class='slds-truncate'][contains(text(),'Accounts')]")
private WebElement mnuAccounts;

private WebUtils objWebUtils = new WebUtils();

public void clickAccountMnu() {
objWebUtils.genericClickAction(mnuAccounts);
}
}


And this gave the following error:

cucumber.runtime.CucumberException: org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'defaultView' of undefined
  (Session info: chrome=78.0.3904.97)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'UK-C02X1E3SJG5J', ip: '10.160.113.245', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_151'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 78.0.3904.97, chrome: {chromedriverVersion: 77.0.3865.40 (f484704e052e0..., userDataDir: /var/folders/13/z0r6r6611wz...}, goog:chromeOptions: {debuggerAddress: localhost:49252}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: bde4eaec56b5a466f9fbe2a592b099e3

at cucumber.api.testng.TestNGCucumberRunner.runCucumber(TestNGCucumberRunner.java:69)
at cucumber.api.testng.AbstractTestNGCucumberTests.feature(AbstractTestNGCucumberTests.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.access$000(SuiteRunner.java:40)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:489)
at org.testng.internal.thread.ThreadUtil$1.call(ThreadUtil.java:52)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'defaultView' of undefined
  (Session info: chrome=78.0.3904.97)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'UK-C02X1E3SJG5J', ip: '10.160.113.245', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_151'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 78.0.3904.97, chrome: {chromedriverVersion: 77.0.3865.40 (f484704e052e0..., userDataDir: /var/folders/13/z0r6r6611wz...}, goog:chromeOptions: {debuggerAddress: localhost:49252}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: bde4eaec56b5a466f9fbe2a592b099e3
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
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 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:51)
at com.sun.proxy.$Proxy19.click(Unknown Source)
at toolspecificlibrary.WebUtils.genericClickAction(WebUtils.java:9)
at designpattern.SaleforceHomePage.clickAccountMnu(SaleforceHomePage.java:31)
at bdd.stepDefinitions.WebSalesforce.click_the_accounts_menu_option(WebSalesforce.java:87)
at ✽.When Click the Accounts menu option(SalesforceCreateAccount.feature:10)


Second Attempt

After the error above, I changed the code to use JavascriptExecutor, as below:

package designpattern;

import base.WebBaseBDD;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import toolspecificlibrary.WebUtils;

public class SaleforceHomePage extends WebBaseBDD {
public SaleforceHomePage(WebDriver driver) {
this.webDriver = driver;
PageFactory.initElements(driver, this);
}

/**
* Locators for the Home Page are defined in this class
*/

@FindBy(xpath = "//span[@class='slds-truncate'][contains(text(),'Accounts')]")
private WebElement mnuAccounts;

private WebUtils objWebUtils = new WebUtils();

public void clickAccountMnu() {
//Creating the JavascriptExecutor interface object by Type casting
JavascriptExecutor jse = (JavascriptExecutor)webDriver;
jse.executeScript("arguments[0].click();", mnuAccounts);
}
}

The above code executes and doesn't error, however, I can see from the driver browser that the Account menu item is not being clicked.

Anyone come across this issue before - be great to know how you overcame it - Thanks!








Screenshot 2019-11-11 at 16.25.28.png

secretsurfspot

unread,
Nov 12, 2019, 7:00:53 AM11/12/19
to Selenium Users
I've managed to get this working by using FireFox - it now hits the Accounts menu element - but wont work with Chrome.

Alex K

unread,
Nov 12, 2019, 8:51:03 AM11/12/19
to Selenium Users
the exception happens in genericClickAction method. Can you post the implementation of that method?
Message has been deleted

secretsurfspot

unread,
Nov 13, 2019, 3:56:26 AM11/13/19
to Selenium Users
Here's the genericClickAction method:

public void genericClickAction(WebElement btnClick) {
btnClick.click();
}

Tricia Crichton

unread,
Nov 13, 2019, 6:22:21 AM11/13/19
to Selenium Users
We've had several issues come up with Salesforce. Several core javascript objects are redefined by the site, and this breaks the Javascript used by ChromeDriver. Several of these issues were fixed in version 78, but your error shows chromedriverVersion: 77.0.3865.40. Upgrading to ChromeDriver 78 may resolve your issue, and if not, please file a bug against ChromeDriver: https://bugs.chromium.org/p/chromedriver/issues/list

secretsurfspot

unread,
Nov 13, 2019, 11:01:59 AM11/13/19
to Selenium Users
I upgraded to chromedriver v78, but it still fails - errors below:

cucumber.runtime.CucumberException: org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'defaultView' of undefined
  (Session info: chrome=78.0.3904.97)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'UK-C02X1E3SJG5J', ip: '10.160.113.245', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_151'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 78.0.3904.97, chrome: {chromedriverVersion: 78.0.3904.70 (edb9c9f3de024..., userDataDir: /var/folders/13/z0r6r6611wz...}, goog:chromeOptions: {debuggerAddress: localhost:49419}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: f991ec829ae0c56bca5c3ed378bc6451
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 78.0.3904.97, chrome: {chromedriverVersion: 78.0.3904.70 (edb9c9f3de024..., userDataDir: /var/folders/13/z0r6r6611wz...}, goog:chromeOptions: {debuggerAddress: localhost:49419}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: f991ec829ae0c56bca5c3ed378bc6451
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
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 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:51)
at com.sun.proxy.$Proxy35.click(Unknown Source)
at toolSpecificLibrary.web.WebUtils.genericClickAction(WebUtils.java:36)
at designPattern.pageFactory.web.salesforce.SalesforceHomePage.clickAccountMnu(SalesforceHomePage.java:29)
at tests.bdd.stepDefinitions.salesforce.WebSalesforce.click_the_accounts_menu_option(WebSalesforce.java:79)
at ✽.When Click the Accounts menu option(SalesforceCreateNewAccount.feature:10)

I'll file a bug as suggested 

Thanks Alex & Tricia for your help :)

secretsurfspot

unread,
Nov 22, 2019, 7:05:23 AM11/22/19
to Selenium Users
This is no longer an issue.

I believe it's because the Devs here have modified the Salesforce instance I'm scripting against.

So the issues wasn't with Selenium after all.
Reply all
Reply to author
Forward
0 new messages