ElementNotVisibleException due to multiple input elements - cucumber-jvm

I have a geb-cucumber scenario which in some point tries to insert a string in an input field of a Frame.
The problem is that the frame has many identical inputs (!!) for some reason and looks something like
<input aria-labeledby="userid-label" aria-required="true" autocomplete="off" class="error input" tabindex="51" type="text" id="el3fd4c7bd50db061c" maxlength="48" aria-invalid="true" aria-describedby="gwt-uid-63">
<input aria-labeledby="userid-label" aria-required="true" autocomplete="off" class="error input" tabindex="51" type="text" id="el3fd4c7bd50db061c" maxlength="48" aria-invalid="true" aria-describedby="gwt-uid-63">
<input aria-labeledby="userid-label" aria-required="true" autocomplete="off" class="error input" tabindex="51" type="text" id="el3fd4c7bd50db061c" maxlength="48" aria-invalid="true" aria-describedby="gwt-uid-63">
In the Chrome devtools console if I give $("input[name=xxx]) it returns the elem and then keep throwing the following message
VM5451:1 Uncaught SyntaxError: Unexpected token # in JSON at position 0
at JSON.parse (<anonymous>)
at i (application-2a3801d….js:11)
this might be irrelevant as my purpose is to just get the element and insert a string into.
getArrayField(userIdField) << "aabbcc"
The getArrayField seems to try to workaround that but it doesnt really work.
The test fails with the following stacktrace
org.openqa.selenium.ElementNotVisibleException: element not visible
(Session info: chrome=60.0.3112.113)
(Driver info: chromedriver=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux 4.11.12-200.fc25.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.5.2', revision: '10229a9', time: '2017-08-21T17:29:55.15Z'
System info: host: 'iob-4finance', ip: '192.168.175.6', os.name: 'Linux', os.arch: 'amd64', os.version: '4.11.12-200.fc25.x86_64', java.version: '1.8.0_131'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5), userDataDir=/tmp/.org.chromium.Chromium.2ksxEt}, takesHeapSnapshot=true, pageLoadStrategy=normal, unhandledPromptBehavior=, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=60.0.3112.113, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 85a17386757827e393d4f83772a88959
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:82)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:45)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:641)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:275)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:99)
at geb.navigator.NonEmptyNavigator$_leftShift_closure30.doCall(NonEmptyNavigator.groovy:448)
at geb.navigator.NonEmptyNavigator.leftShift(NonEmptyNavigator.groovy:447)
at geb.content.TemplateDerivedPageContent.leftShift(TemplateDerivedPageContent.groovy:27)
at com.ofg.loans.dk.at.web.site.pages.IdentificationPage.logIntoNemIdApp(IdentificationPage.groovy:40)
at com.ofg.loans.dk.at.web.site.pages.IdentificationPage$logIntoNemIdApp.call(Unknown Source)
at com.ofg.loans.dk.at.web.site.stepdefs.nemid.NemIdStepDefs$_run_closure3.doCall(NemIdStepDefs.groovy:47)
at ✽.And user logs into NemId from the webapp(com/at/web/features/.feature:13)
You can also reproduce the problem at https://service.nemid.nu/dk-en/#log_on_to_self-service which is the identification service used. I could use any help or direction to the proper solution. thanks

I don't see a name field in your sample HTML. But if there is a name field, try using this in the Chrome developer tools:
$("input[name='xxx']")
And this in Geb:
$("input", name: "xxx")
Also, it seems you might be using a # as part of the name. Make sure to escape the character with \#
Another option is if the elements are always in the same order, you can use the eq selector:
$("input[name='xxx']").eq(0)

Related

Chrome Headless element not visible

I am facing following error while trying to interact one editbox inside an iframe.
Please note code is working fine, if I don't run that it in headless mode. Issue only occurs when I run in headless mode.
Error:
org.openqa.selenium.ElementNotVisibleException: element not visible
Stacktrace:
org.openqa.selenium.ElementNotVisibleException: element not visible
(Session info: headless chrome=60.0.3112.113)
(Driver info: chromedriver=2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4),platform=Linux 4.9.51-10.52.amzn1.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 21 milliseconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'ip-172-31-41-152', ip: '172.31.41.152', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.51-10.52.amzn1.x86_64', java.version: '1.8.0_45'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4), userDataDir=/tmp/.org.chromium.Chromium.aRCh3q}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=60.0.3112.113, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}]
Session ID: ebc4a4ce4a038d2440aedb1f4d952a64
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:422)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:85)
at com.medexpress.pages.Buyer.CheckoutPage.submitPage(CheckoutPage.java:148)
at com.medexpress.steps.Order.Submits_the_order(Order.java:120)
at ✽.And Submits the order(com/medexpress/steps/2oder_checkout.feature:44)
To solve this issue, I am trying to scroll to that Iframe or the element which will bring this iframe in focus. I have tried following things. However nothing is working. it's not scrolling to given element.
Scroll Using Native Events
actions.moveToElement(element).build().perform();
Scroll using JavaScript
Actions actions = new Actions(driver);
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].scrollIntoView()", element);
Scroll to end of page using javascript
js.executeScript("window.scrollTo(0,document.body.scr‌​ollHeight);");
above code is not working and gives following error.
org.openqa.selenium.WebDriverException: unknown error: Runtime.evaluate threw exception: SyntaxError: Invalid or unexpected token
Please note that all the above code is working on chrome, only issue with headless.
Drive Code
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("headless");
chromeOptions.addArguments("disable-gpu");
chromeOptions.addArguments("window-size=1200,1100");
driver = new ChromeDriver(chromeOptions);
If an element is visible (it has height and width greater than 0), it clicks that element without the need to scroll.
I had the same issue, and fixed it by making the window as FullHD, so just change this line:
chromeOptions.addArguments("window-size=1200,1100");
to
chromeOptions.addArguments("window-size=1980,1080");
Don't know the syntax of Java since I fixed it in C#, but it's worth the try.
Faced similar issue. The following lines of code worked for me -
options.addArguments("--proxy-server='direct://'");
options.addArguments("--proxy-bypass-list=*");
Source - https://github.com/Codeception/CodeceptJS/issues/561
Increasing the "window-size" fixed the error in the Gulp-Protractor
browserName: 'chrome',
chromeOptions: {
args: [ "--headless", "--disable-gpu", "--window-size=1200,900" ]
}

Selenium: How to click on href link when it wont have absolute path

I am trying to identify a link in the CQ5 webpage and click on it.
Below is the html code:
<a href="/siteadmin" title="Websites">
<div class="icon siteadmin">
<div class="title">Websites</div>
<div class="description">Create and manage multiple websites.
</div>
</div>
</a>
The below are method i tried to find the information and click on it.
driver.findElement(By.linkText("Websites")).click();
driver.findElement(By.xpath("//a[#href='/siteadmin']")).click();
Getting following exception:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (528, 174). Other element would receive the click: <div class="resourcebox">...</div>
(Session info: chrome=52.0.2743.116)
(Driver info: chromedriver=2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 39 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:32:46'
System info: host: 'pilapwin7020', ip: '10.116.252.187', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_101'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b), userDataDir=C:\Users\User\AppData\Local\Temp\scoped_dir44444_30971}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=52.0.2743.116, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 5116ba44126c39293ac466aed3d6608a
You should try using JavascriptExecutor to perform click in this case as :-
((JavascriptExecutor)driver).executeScript("arguments[0].click()", driver.findElement(By.cssSelector("a[href = '/siteadmin'][title = 'Websites']")));
You need to check if the attr contains the string, because it returns the fullpath even if in the HTML shows only /siteadmin.
XPath Solution:
//a[contains(#href, '/siteadmin') and #title='Websites']
Css Selector Solution:
a[href*='/siteadmin'][title='Websites']

Selenium WebDriver: Unable to Select Element

<input type="text" id="mobile" name="mobile" placeholder="Mobile Number" maxlength="10" value="" onkeyup="javascript:dispLocMob(this);" onkeydown="javascript:dispLocMob(this);" onchange="javascript:dispLocMob(this);">
Shown above is the element that I'm trying to send keys. I tried by xpath and id and all sorts of selectors, but it throws an error that is shown below:
Unable to locate element: {"method":"xpath","selector":"/html/body/div[3]/div/form/div[2]/div[1]/input"}
Command duration or timeout: 338 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'ClaimsCM8', ip: '192.168.110.118', os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.7.0_51'
*** Element info: {Using=xpath, value=/html/body/div[3]/div/form/div[2]/div[1]/input}
Session ID: ec543fff-7116-4880-8c98-7c60a1c697d0
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=45.0.2}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:500)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
at Selenium.Test2.main(Test2.java:62)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"/html/body/div[3]/div/form/div[2]/div[1]/input"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'ClaimsCM8', ip: '192.168.110.118', os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.7.0_51'
Driver info: driver.version: unknown
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/EFERNA~1/AppData/Local/Temp/anonymous4369679942726534324webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:10770)
at <anonymous class>.FirefoxDriver.prototype.findElement(file:///C:/Users/EFERNA~1/AppData/Local/Temp/anonymous4369679942726534324webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:10779)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/EFERNA~1/AppData/Local/Temp/anonymous4369679942726534324webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12661)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/Users/EFERNA~1/AppData/Local/Temp/anonymous4369679942726534324webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12666)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/Users/EFERNA~1/AppData/Local/Temp/anonymous4369679942726534324webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12608)
Is there something defined in the Web Element that does not let me access the element in my Selenium script?
Any suggestions/advice will be highly appreciated.
Thanks you!
Try as below :-
WebDriverWait wait = new WebDriverWait(driver, 10);
el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("mobile")));
el.sendKeys("your value");
Note :- Be ensure before finding element that it is not inside any frame or iframe. If it is inside any frame or iframe you need to switch that frame first as :- driver.switchTo().frame("frame name or id")
Hope it will help you...:)
First of all, If you are using xpaths then use relative xpath instead of absolute as slight change in DOM makes absolute xpaths invalid or refer to a wrong element.
Second try using .click(); before .sendkeys();. So your code can be something like
WebElement ele = dvr.findElement(By.id("mobile"));
ele.click();
ele.sendKeys("your string");
Lastly, make sure you do not have any duplicate elements on the page with same property, i.e. id=="mobile". Hope this helps
Please try below code:
If the element is not in any frame:
driver.findElement(By.id("mobile")).sendKeys("");
If the element is inside a frame:
// Switching to the frame
driver.switchTo().frame(<framename>);
driver.findElement(By.id("mobile")).sendKeys("");
driver.switchTo().defaultContent();
Also, please add some wait after launching the page and entering the text. And even if the code is not working, please check whether the element is visible or not using below code:
if(driver.findElement(By.id("mobile")).isDisplayed()) {
// Add the code given above
}
Hope this helps

protractor NoSuchElementError: no such element

When I was try to send keys in non-angular page with protractor it shows an error "NoSuchElementError: no such element"
NoSuchElementError: no such element
(Session info: chrome=47.0.2526.80)
(Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 24 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'Sekhar-PC', ip: '192.168.1.3', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_13'
* Element info: {Using=id, value=ius-userids}
Session ID: 352e36f285f80dee03eb5c88697ebc08
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\Sekhar\AppData\Local\Temp\scoped_dir3128_18281}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=47.0.2526.80, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}]
**
When testing non-Angular pages with Protractor, you need to include this line in all of your specs:
browser.ignoreSynchronization = true;
You also need to wait for the page to completely load. Using ExpectedConditions is one way to do that. Example:
var EC = protractor.ExpectedConditions;
browser.wait(EC.elementToBeClickable(element(by.css('.wait-for-me'))), 10000);
Use sleep condition.
browser.driver.sleep(500);
This will wait the browser for sometime.
Looks like timing issue, write some "expect" statements so that it will verify for particular functionality is available.
Try to use implicit wait.
Try writing your script in promises so that it will wait.
field.sendKeys(value).then(function(){
submitButton.click().then(function(){
expect('xyz').toBe(xyz);
});
});

Selenium Webdriver | Unable to locate 'href' element

I am trying to locate below link in Selenium Webdriver using Xpath and CSS.
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<tr>
<td class="cspbItmA">
<a class="cspbItm" target="_parent" href="../isp_track.asp?PARENT_MENU=Customer Order">Find Order</a>
</td>
</tr>
But neither of these options, I am unable to run the script and trapped with below exception:
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[#id='cspbGrp0']/table/tbody/tr[2]/td/a")) .click();
Starting ChromeDriver (v2.9.248315) on port 8139 Exception in thread
"main" org.openqa.selenium.NoSuchElementException: no such element
(Session info: chrome=40.0.2214.115) (Driver info:
chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86) (WARNING: The
server did not provide any stacktrace information) Command duration or
timeout: 5.06 seconds For documentation on this error, please visit:
http://seleniumhq.org/exceptions/no_such_element.html Build info:
version: '2.42.0', revision:
'5e824302019c86eae9c8c3ca9155e7307b410cf8', time: '2014-05-24
09:48:41' System info: host: 'inl-279930-1', ip: '10.13.174.254',
os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version:
'1.7.0_55' Session ID: 04489825ed0cfc399afa1ffccb838870 Driver info:
org.openqa.selenium.chrome.ChromeDriver Capabilities [{platform=XP,
acceptSslCerts=true, javascriptEnabled=true, browserName=chrome,
chrome={userDataDir=C:\Users\SUBRAM~1\AppData\Local\Temp\scoped_dir11808_15574},
rotatable=false, locationContextEnabled=true, version=40.0.2214.115,
takesHeapSnapshot=true, cssSelectorsEnabled=true,
databaseEnabled=false, handlesAlerts=true,
browserConnectionEnabled=false, nativeEvents=true,
webStorageEnabled=true, applicationCacheEnabled=false,
takesScreenshot=true}] at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at
org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:596)
at
org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:349)
at
org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:446)
at org.openqa.selenium.By$ByXPath.findElement(By.java:357) at
org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:341)
at roll_forward_test.cpe_progression.main(cpe_progression.java:147)
Could you help me to get this fixed, please.
My preference would be to use css over xpath and I would usually write my own selectors. Because it's in a table it can be a little tricky (meaning you may have to traverse from further up) but from the information on screen I'd go for something like:
//by href
driver.findElement(By.cssSelector("a[href='../isp_track.asp?PARENT_MENU=Customer Order']"))
OR
//by class
driver.findElement(By.cssSelector("a.cspbItm"))
Issue identified and it is caused due to the element present inside an iFrame.
When switching to iFrame first, now able to locate the element.
Thank You,
Praveen