Search a value from Lookup button and select the result

Hi, I am trying to automate salesforce and have a look up button on account page. I give a value eg: 1111 in the text area and click on lookup icon. SwitchToWindowTitle(1) and then select the value from the list and switch back to the previous window. Now when I try to automate it, I’m getting stuck on selecting the value from the list.
Katalon neither selects the value nor switch back to the previous window and I get the below error message

“Unable to find the element located by 'By.xpath. Please recheck the objects properties to make sure the desired element is located.”

I tried spying the Xpath and elements but didn’t work. Please help.

@aaradhya.keerty Can you please post the Script, HTML of the list with other relevant information ?

The error says that the xpath is not correct. We can try to manually create the xpath using inspect element. It seems it is failing at this step and won’t go to next step which is switch to window.

@manpreet.mukkar Thank you for your response. Please find the script below.

WebUI.setText(findTestObject(‘Object Repository/Account Creation/Page_Account Edit New Account Salesforce - Unlimited Edition/input_SIC Code_CF00N30000001dOEO’),
‘6011’)

WebUI.click(findTestObject(‘Object Repository/Account Creation/Page_Account Edit New Account Salesforce - Unlimited Edition/img_SIC Code_lookupIconOn’))

WebUI.delay(3)

WebUI.switchToWindowTitle(‘Account Edit: New Account ~ Salesforce - Unlimited Edition’)

WebUI.setText(findTestObject(‘Object Repository/Account Creation/Page_Account Edit New Account Salesforce - Unlimited Edition/input_SIC Code_CF00N30000001dOEO’),
‘6011’)

WebUI.click(findTestObject(‘Object Repository/Account Creation/Page_Search Salesforce - Unlimited Edition/a_6011’))

WebUI.switchToWindowTitle(‘Account Edit: New Account ~ Salesforce - Unlimited Edition’)

@aaradhya.keerty Why this step is repeating after you switch to window with title “Account Edit: New Account ~ Salesforce - Unlimited Edition”

From your 1st post, I was under impression that you want to select text from the list that shows up on new windows after you will click on Lookup icon and switch back to the previous window.

Also in the last step you are using

But you are already on the same window.

Sorry I didn’t realize that I did not post the entire script. Please find the script below

WebUI.setText(findTestObject(‘Object Repository/Account Creation/Page_Account Edit New Account Salesforce - Unlimited Edition/input__acc2’),
‘Automation_Test1’)

WebUI.selectOptionByValue(findTestObject(‘Object Repository/Account Creation/Page_Account Edit New Account Salesforce - Unlimited Edition/select_Type’),
‘Customer’, true)

WebUI.selectOptionByValue(findTestObject(‘Object Repository/Account Creation/Page_Account Edit New Account Salesforce - Unlimited Edition/select_Account Product Mix’),
‘Medical’, true)

WebUI.selectOptionByValue(findTestObject(‘Object Repository/Account Creation/Page_Account Edit New Account Salesforce - Unlimited Edition/select_Sales Office’),
‘San Jose’, true)

WebUI.selectOptionByValue(findTestObject(‘Object Repository/Account Creation/Page_Account Edit New Account Salesforce - Unlimited Edition/select_Core Fee Rating Basis’),
‘Mature’, true)

WebUI.setText(findTestObject(‘Object Repository/Account Creation/Page_Account Edit New Account Salesforce - Unlimited Edition/input_Tax ID_00N30000005HjZp’),
‘9887776666’)

WebUI.setText(findTestObject(‘Object Repository/Account Creation/Page_Account Edit New Account Salesforce - Unlimited Edition/input_Facets Group ID_00N30000006Rybz’),
‘W3344232’)

//SIC Code

WebUI.setText(findTestObject(‘Object Repository/Account Creation/Page_Account Edit New Account Salesforce - Unlimited Edition/input_SIC Code_CF00N30000001dOEO’),
‘6011’)

WebUI.click(findTestObject(‘Object Repository/Account Creation/Page_Account Edit New Account Salesforce - Unlimited Edition/img_SIC Code_lookupIconOn’))

WebUI.delay(3)

WebUI.switchToWindowTitle(‘Account Edit: New Account ~ Salesforce - Unlimited Edition’)

WebUI.setText(findTestObject(‘Object Repository/Account Creation/Page_Account Edit New Account Salesforce - Unlimited Edition/input_SIC Code_CF00N30000001dOEO’),
‘6011’)

WebUI.click(findTestObject(‘Object Repository/Account Creation/Page_Search Salesforce - Unlimited Edition/a_6011’))

WebUI.switchToWindowTitle(‘Account Edit: New Account ~ Salesforce - Unlimited Edition’)

WebUI.setText(findTestObject(‘Object Repository/Account Creation/Page_Account Edit New Account Salesforce - Unlimited Edition/textarea_Mailing Street_acc17street’),
‘33 Union Square’)

@aaradhya.keerty Can you please answer my queries in this post

@manpreet.mukkar Your understanding is correct. I do want to select the “code” from the list that populates when I enter a value and click on lookup and switch back to main window.

I’m not sure why this step is repeating every time I record, But when I click on the desired code from the list, it automatically populated this step again.

@aaradhya.keerty I got it now you are using record and playback option. Can you also share the HTML of the list from where you want to select the text ?

Also for the Switch to Window Title I looks like it is not actually recording the switch properly. From your code you are switching to the window on where you already are. To overcome these scenarios you can manually create the object and use script mode to accomplish that. I would need a lot more information to make it work.

Here is what is needed :

  • HTML code of the list that populates the code. Right-click on the code which you want to select from the list and click on Inspect Element. It will open developer tools and then from there, you can see what are the selectors available. Something like this :

  • Title of every window that will show up. e.g when you click lookup icon it will open a new window. I would need the title of that Window. I would need to know the title of the window which was initially open to switching back to that window.

@manpreet.mukkar Please find the HTML for the selected item in search result.

Search Results
SIC Code Major Industry Sub-Group Specific Line of Business Category Medical Rx
6011 Fin. Ins. & Real Est Deposit Instit Federal Reserve Banks Standard 1.00 1.00
Copyright © 2000-2019 salesforce.com, inc. All rights reserved.

The tile of the look up window is below

image

Title of first window is

@aaradhya.keerty I can’t see the HTML. I am only able to see screenshot.

Can you post the html the way I shared above

@aaradhya.keerty

Follow these instructions to post HTML

See Section 5: (MUST READ FIRST) Global Forum Rules

@manpreet.mukkar Thanks for helping out on this

<html style=""><script src="chrome-extension://ljdobmomdgdljniojadhoplhkpialdid/page/prompt.js"></script><script src="chrome-extension://ljdobmomdgdljniojadhoplhkpialdid/page/runScript.js"></script><head><script src="/static/111213/js/perf/stub.js"></script>
<title></title><meta http-equiv="PRAGMA" content="NO-CACHE"><script src="/jslibrary/1563215524220/sfdc/main.js"></script><script src="/jslibrary/jslabels/1564435338000/en_US.js"></script><script src="/jslibrary/1553583056220/sfdc/SearchOnly.js"></script><script>window.sfdcPage = new GenericSfdcPage();
UserContext.initialize({"ampm":["AM","PM"],"isAccessibleMode":false,"salesforceURL":"https://blueshieldca--SLCqa2.cs26.my.salesforce.com","dateFormat":"M/d/yyyy","language":"en_US","locale":"en_US","dateTimeFormat":"M/d/yyyy h:mm a","isGlobalEventBusPilotEnabled":false,"labelLastModified":"1564435338000","today":"7/31/2019 1:32 PM","userPreferences":[{"index":112,"name":"HideInlineEditSplash","value":false},{"index":114,"name":"OverrideTaskSendNotification","value":false},{"index":115,"name":"DefaultTaskSendNotification","value":false},{"index":119,"name":"HideUserLayoutStdFieldInfo","value":false},{"index":116,"name":"HideRPPWarning","value":false},{"index":87,"name":"HideInlineSchedulingSplash","value":false},{"index":88,"name":"HideCRUCNotification","value":false},{"index":89,"name":"HideNewPLESplash","value":false},{"index":90,"name":"HideNewPLEWarnIE6","value":false},{"index":122,"name":"HideOverrideSharingMessage","value":false},{"index":91,"name":"HideProfileILEWarn","value":false},{"index":93,"name":"HideProfileElvVideo","value":false},{"index":97,"name":"ShowPicklistEditSplash","value":false},{"index":92,"name":"HideDataCategorySplash","value":false},{"index":128,"name":"ShowDealView","value":false},{"index":129,"name":"HideDealViewGuidedTour","value":false},{"index":132,"name":"HideKnowledgeFirstTimeSetupMsg","value":false},{"index":104,"name":"DefaultOffEntityPermsMsg","value":false},{"index":135,"name":"HideNewCsnSplash","value":false},{"index":101,"name":"HideBrowserWarning","value":false},{"index":139,"name":"HideDashboardBuilderGuidedTour","value":false},{"index":140,"name":"HideSchedulingGuidedTour","value":false},{"index":180,"name":"HideReportBuilderGuidedTour","value":false},{"index":183,"name":"HideAssociationQueueCallout","value":false},{"index":194,"name":"HideQTEBanner","value":false},{"index":270,"name":"HideIDEGuidedTour","value":false},{"index":282,"name":"HideQueryToolGuidedTour","value":false},{"index":196,"name":"HideCSIGuidedTour","value":false},{"index":271,"name":"HideFewmetGuidedTour","value":false},{"index":272,"name":"HideEditorGuidedTour","value":false},{"index":205,"name":"HideApexTestGuidedTour","value":false},{"index":206,"name":"HideSetupProfileHeaderTour","value":false},{"index":207,"name":"HideSetupProfileObjectsAndTabsTour","value":false},{"index":213,"name":"DefaultOffArticleTypeEntityPermMsg","value":false},{"index":214,"name":"HideSelfInfluenceGetStarted","value":false},{"index":215,"name":"HideOtherInfluenceGetStarted","value":false},{"index":216,"name":"HideFeedToggleGuidedTour","value":false},{"index":268,"name":"ShowChatterTab178GuidedTour","value":false},{"index":275,"name":"HidePeopleTabDeprecationMsg","value":false},{"index":276,"name":"HideGroupTabDeprecationMsg","value":false},{"index":224,"name":"HideUnifiedSearchGuidedTour","value":false},{"index":226,"name":"ShowDevContextMenu","value":false},{"index":227,"name":"HideWhatRecommenderForActivityQueues","value":false},{"index":228,"name":"HideLiveAgentFirstTimeSetupMsg","value":false},{"index":232,"name":"HideGroupAllowsGuestsMsgOnMemberWidget","value":false},{"index":233,"name":"HideGroupAllowsGuestsMsg","value":false},{"index":234,"name":"HideWhatAreGuestsMsg","value":false},{"index":235,"name":"HideNowAllowGuestsMsg","value":false},{"index":236,"name":"HideSocialAccountsAndContactsGuidedTour","value":false},{"index":237,"name":"HideAnalyticsHomeGuidedTour","value":false},{"index":238,"name":"ShowQuickCreateGuidedTour","value":false},{"index":245,"name":"HideFilePageGuidedTour","value":false},{"index":250,"name":"HideForecastingGuidedTour","value":false},{"index":251,"name":"HideBucketFieldGuide","value":false},{"index":263,"name":"HideSmartSearchCallOut","value":false},{"index":273,"name":"ShowForecastingQuotaAttainment","value":false},{"index":280,"name":"HideForecastingQuotaColumn","value":false},{"index":301,"name":"HideManyWhoGuidedTour","value":true},{"index":298,"name":"HideFileSyncBannerMsg","value":false},{"index":299,"name":"HideTestConsoleGuidedTour","value":false},{"index":302,"name":"HideManyWhoInlineEditTip","value":false},{"index":303,"name":"HideSetupV2WelcomeMessage","value":false},{"index":312,"name":"ForecastingShowQuantity","value":false},{"index":313,"name":"HideDataImporterIntroMsg","value":false},{"index":314,"name":"HideEnvironmentHubLightbox","value":false},{"index":316,"name":"HideSetupV2GuidedTour","value":false},{"index":317,"name":"HideFileSyncMobileDownloadDialog","value":false},{"index":322,"name":"HideEnhancedProfileHelpBubble","value":false},{"index":328,"name":"ForecastingHideZeroRows","value":false},{"index":330,"name":"HideEmbeddedComponentsFeatureCallout","value":false},{"index":341,"name":"HideDedupeMatchResultCallout","value":true},{"index":340,"name":"HideS1BrowserUI","value":false},{"index":346,"name":"HideS1Banner","value":false},{"index":358,"name":"HideEmailVerificationAlert","value":false},{"index":354,"name":"HideLearningPathModal","value":false},{"index":359,"name":"HideAtMentionsHelpBubble","value":false},{"index":368,"name":"LightningExperiencePreferred","value":false},{"index":373,"name":"PreviewLightning","value":false}],"networkId":"","uiTheme":"Theme3","uiSkin":"Theme3","userName":"aaradhya.keerty@blueshieldca.com.slcqa2","userId":"00521000002VcZK","isCurrentlySysAdminSU":false,"renderMode":"RETRO","startOfWeek":"1","vfDomainPattern":"blueshieldca--SLCqa2--(?:[^.]+).cs26.visual.force.com","auraDomain":"blueshieldca--SLCqa2.lightning.force.com","orgPreferences":[{"index":257,"name":"TabOrganizer","value":true},{"index":113,"name":"GroupTasks","value":true}],"siteUrlPrefix":"","isDefaultNetwork":true,"timeFormat":"h:mm a"});
</script><link href="/sCSS/46.0/sprites/1562794536000/Theme3/default/gc/zen-componentsCompatible.css" rel="stylesheet" type="text/css"><link href="/sCSS/46.0/sprites/1562794536000/Theme3/default/gc/elements.css" rel="stylesheet" type="text/css"><link href="/sCSS/46.0/sprites/1562794536000/Theme3/default/gc/common.css" rel="stylesheet" type="text/css"><link href="/sCSS/46.0/sprites/1563284246000/Theme3/gc/dStandard.css" rel="stylesheet" type="text/css"><link href="/sCSS/46.0/sprites/1563284246000/Theme3/00D210000009xQr/00521000002VcZK/gc/dCustom0.css" rel="stylesheet" type="text/css"><link href="/sCSS/46.0/sprites/1563284246000/Theme3/00D210000009xQr/00521000002VcZK/gc/dCustom1.css" rel="stylesheet" type="text/css"><link href="/sCSS/46.0/sprites/1563284246000/Theme3/00D210000009xQr/00521000002VcZK/gc/dCustom2.css" rel="stylesheet" type="text/css"><link href="/sCSS/46.0/sprites/1563284246000/Theme3/00D210000009xQr/00521000002VcZK/gc/dCustom3.css" rel="stylesheet" type="text/css"><link href="/sCSS/46.0/sprites/1562794536000/Theme3/default/gc/extended.css" rel="stylesheet" type="text/css"><script type="text/javascript">
//<![CDATA[
try{(function(){var w=self,l,p,o;if(w&&top){for(;w!==top&&(p=w.parent)&&p!==w&&(o=p.location)&&o.protocol===(l=w.location).protocol&&(o.host===l.host||(p.document&&p.document.domain===w.document.domain));w=p);if(w!==top)throw "";}({f:function(){document.documentElement?document.documentElement.style.display="":(!this.a&&(this.a=10),this.a<1E5&&(window.sfdcRetryShowWindow=this)&&setTimeout("sfdcRetryShowWindow.f()",this.a),this.a*=2)}}.f())})();}catch(e){if(top!==self)top.location=location;else throw e;}//]]></script><link rel="shortcut icon" href="https://blueshieldca--SLCqa2.cs26.my.salesforce.com/favicon.ico">
<script src="/jslibrary/1553583056220/sfdc/Security.js"></script><script>ClientHash.prototype.needsClientHash('sid_Client','1000002VcZK10000009xQr','165.253.64.70','/servlet/servlet.ClientHashValidator?ResponseRequestedURL=%2F_ui%2Fcommon%2Fdata%2FLookupResultsFrame%3Flktp%3Da00%26lkfm%3DeditPage%26lknm%3DCF00N30000001dOEO%26lksrch%3D6011');</script></head><body onunload="if(this.bodyOnUnload)bodyOnUnload();" onbeforeunload="if(this.bodyOnBeforeUnload){var s=bodyOnBeforeUnload();if(s)return s;}" onload="if(this.bodyOnLoad)bodyOnLoad();" class="hasMotif lookupTab  LookupResultsFrame" onfocus="if(this.bodyOnFocus)bodyOnFocus();" marginwidth="0" marginheight="0">
<!-- Main Body Starts Here -->
<form accept-charset="UTF-8" action="/_ui/common/data/LookupResultsFrame" enctype="application/x-www-form-urlencoded" id="new" method="GET" name="new" onsubmit="if (window.ffInAlert) { return false; } return disableLookupButtons()"><input type="hidden" name="_CONFIRMATIONTOKEN" id="_CONFIRMATIONTOKEN" value="VmpFPSxNakF4T1Mwd09DMHdNMVF5TURvek1qb3dPUzQzTWpOYSxYYmo0RElzT1A4QUNKY3doMmY5ckU4LE5tWXlPV1Zq"><input type="hidden" name="lkenhmd" id="lkenhmd" value="SEARCH_NAME"><input type="hidden" name="lkfm" id="lkfm" value="editPage"><input type="hidden" name="lknm" id="lknm" value="CF00N30000001dOEO"><input type="hidden" name="lksrch" id="lksrch" value="6011"><input type="hidden" name="lktp" id="lktp" value="a00"><div class="lookup"><div class="clearResults">&lt; <script>function clearSearch() {parent.searchFrame.document.theForm.lksrch.value='';var loc = window.location.toString();var qs = QueryString.createQueryString(loc);qs.add('lksrch','');window.location = QueryString.getURI(loc)+qs.toString();}</script><a href="javascript:clearSearch%28%29%3B">Clear Search Results</a></div><div class="srch">Search Results</div>
<!-- Begin ListElement -->

<!-- motif: Lookup -->

<!-- WrappingClass -->
<div class="listRelatedObject lookupBlock"><div class="bPageBlock brandSecondaryBrd secondaryPalette"><div class="pbHeader"></div><div class="pbBody"><table class="list" border="0" cellspacing="0" cellpadding="0"><tbody><tr class="headerRow"><th scope="col" class=" zen-deemphasize">SIC Code</th><th scope="col" class=" zen-deemphasize">Major Industry</th><th scope="col" class=" zen-deemphasize">Sub-Group</th><th scope="col" class=" zen-deemphasize">Specific Line of Business</th><th scope="col" class=" zen-deemphasize">Category</th><th scope="col" class="numericalColumn zen-deemphasize">Medical</th><th scope="col" class="numericalColumn zen-deemphasize">Rx</th></tr>
<tr class="dataRow even last first"><th scope="row"><a href="#" class=" dataCell " onclick="top.window.opener.lookupPick('editPage','CF00N30000001dOEO_lkid','CF00N30000001dOEO','','a0021000007l3Ei','6011','','')">6011</a></th><td class=" dataCell  ">Fin. Ins. &amp; Real Est</td><td class=" dataCell  ">Deposit Instit</td><td class=" dataCell  ">Federal Reserve Banks</td><td class=" dataCell  ">Standard</td><td class=" dataCell  numericalColumn">1.00</td><td class=" dataCell  numericalColumn">1.00</td></tr>
</tbody></table>
</div><div class="pbFooter secondaryPalette"><div class="bg"></div></div></div></div><div class="listElementBottomNav"></div>
<!-- End ListElement -->
<div class="footer">Copyright © 2000-2019 salesforce.com, inc. All rights reserved.</div><script>function disableLookupButtons() {var btnBar = document.getElementById(DetailElement.BOTTOM_BUTTON_ROW);if (btnBar) {var btns = btnBar.getElementsByTagName('input');for (var i = 0; i < btns.length; i++) {var btn = btns[i];if (btn.className === 'btnDisabled'){return false;}btn.className = 'btnDisabled';}}return true;}</script></div></form>


<!-- Body events -->
<script type="text/javascript">function bodyOnLoad(){setFocusOnLoad();if(window.PreferenceBits){window.PreferenceBits.prototype.csrfToken="VmpFPSxNakF4T1Mwd09DMHdNMVF5TURvek1qb3dPUzQzTXpkYSxPMkxHVEV2RThsam9SdldIdGJzRnkwLE1HVXdaalF3";};}function bodyOnBeforeUnload(){}function bodyOnFocus(){}function bodyOnUnload(){}</script></body></html>

@aaradhya.keerty I am not able to figure this out from the pasted html. Can you post it in the same way as I posted the Google Screenshot. Highlighting the text using Google Chrome dev tools which will highlight the html for that element.

@manpreet.mukkar Please let me know if this below screenshot works.

@aaradhya.keerty Try this :


WebUI.delay(3)

WebUI.switchToWindowTitle(‘Add Title of the Window from where you want to get the SIC Code')

getSICCode = WebUI.getText(findTestObject(‘Object Repository/Account Creation/Page_Account Edit New Account Salesforce - Unlimited Edition/input_SIC Code_CF00N30000001dOEO’),
‘6011’)

WebUI.println('The SIC Code is : ' + getSICCode)

WebUI.switchToWindowTitle(‘Add Title of the Window where you want to enter SIC Code’)

Please update the title of windows in code. You can get them from title tag. Right Click > View Page Source

@manpreet.mukkar It worked for me. Thank you for helping.

@aaradhya.keerty Glad to hear that.

Don’t forget to select tick if the reply solves your problem.