How to get and Store list item value from drop down and store into Array variable and then call that value

Ask general questions here.
gsb
Posts: 17
Joined: Wed Mar 17, 2021 3:49 pm

How to get and Store list item value from drop down and store into Array variable and then call that value

Post by gsb » Wed Apr 14, 2021 7:17 pm

Requirement for dropdown list

1. To count no of list values in dropdown
2. Store all the list values then into variable(s) (Array if possible)
3. Select any value from that array
4. Verified and log the selected value


XPath //*[@id="OriginatorEmail"]

Full Element Path
<input class="multiselect-input" readonly="" type="text" id="OriginatorEmail" title=""> (Initially none selected)
<input class="multiselect-input" readonly="" type="text" id="OriginatorEmail" title="christy Rich">
<input class="multiselect-input" readonly="" type="text" id="OriginatorEmail" title="Gurpreet Ubhi">
<input class="multiselect-input" readonly="" type="text" id="OriginatorEmail" title="Value Third">
<input class="multiselect-input" readonly="" type="text" id="OriginatorEmail" title="Value Forth">
<input class="multiselect-input" readonly="" type="text" id="OriginatorEmail" title="Value Fifth">
<input class="multiselect-input" readonly="" type="text" id="OriginatorEmail" title="Value Sixth">


on Recorded list for 4rth value
tag[1]/?/?/div/?/?/tag[@tagname='row']/div/tag[2]/tag[@tagname='row']/div/?/?/tag[@tagname='ng-component']/div/tag[@tagname='single-select']/div/div[2]/ul/li[5]/label

on Recorded list for 5th value
tag[1]/?/?/div/?/?/tag[@tagname='row']/div/tag[2]/tag[@tagname='row']/div/?/?/tag[@tagname='ng-component']/div/tag[@tagname='single-select']/div/div[2]/ul/li[6]/label (but it does not work)

only got selected the 4rth one


OR is when tracked
Portal = /dom[@domain='urlname.com']
List selected = .//form[#'loanRegisterShort']/tag[1]/?/?/div/?/?/tag[@tagname='row']/div/tag[2]/tag[@tagname='row']/div/?/?/tag[@tagname='ng-component']/div/tag[@tagname='single-select']/div/div[2]/ul/li[6]/?/?/span[@innertext='Gurpreet Ubhi']


tag[1]/?/?/div/?/?/tag[@tagname='row']/div/tag[2]/tag[@tagname='row']/div/?/?/tag[@tagname='ng-component']/div/tag[@tagname='single-select']/div/div[2]/ul/li[7]/?/?/span[@innertext='Gurpreet Ubhi']

/dom[@domain='weburl.com.com']//form[#'loanRegisterShort']/tag[1]/?/?/div/?/?/tag[@tagname='row']/div/tag[2]/tag[@tagname='row']/div/?/?/tag[@tagname='ng-component']/div/tag[@tagname='single-select']/div/div[2]/ul/li[7]/?/?/span[@innertext='Gurpreet Ubhi']
Attachments
DynamicDropdown.JPG
DynamicDropdown.JPG (19.28 KiB) Viewed 173 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 6544
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to get and Store list item value from drop down and store into Array variable and then call that value

Post by odklizec » Wed Apr 14, 2021 7:45 pm

Hi,

Please upload a Ranorex snapshot (not screenshot) of the list in question. It’s pretty hard to suggest something sensible, without seeing, at very least, a Ranorex snapshot of the problematic element. Thanks.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

gsb
Posts: 17
Joined: Wed Mar 17, 2021 3:49 pm

Re: How to get and Store list item value from drop down and store into Array variable and then call that value

Post by gsb » Wed Apr 14, 2021 10:20 pm

Thanks odklizec

Emailed the snapshot, just to brief here 6th element and UI[6] like this :) what will be approach for this

Thanks pls keep the domain hided

Thanks for help
Attachments
6thelementinlist.JPG
6thelementinlist.JPG (83.88 KiB) Viewed 165 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 6544
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to get and Store list item value from drop down and store into Array variable and then call that value

Post by odklizec » Thu Apr 15, 2021 7:27 am

Hi,

So here is the xpath to all list items:
/dom[@domain='YourDomain']//form[#'loanRegisterShort']//div[@class='row']//div[@class='ng-invalid ng-pristine ng-touched']/tag[@class='ng-invalid ng-pristine ng-touched']/?/?/div[@class='multiselect-wrapper']/div[@class='multiselect-list']//span

Now you need to use foreach loop to obtain individual list items and get their innertexts. Ideally, use method with repoInfoElement as a parameter to which you should pass repo element with above xpath...

Code: Select all

		public void GetListItems(RepoItemInfo selectItemsInfo)
		{
			string listItemInnerText;
			IList <SpanTag> selectItemsList = selectItemsInfo.CreateAdapters<Ranorex.SpanTag>();
			foreach (Ranorex.SpanTag selectItem in selectItemsList)
			{
				//do whatever you want with obtained select item ;)
				//in this case, it will get InnerText of currently accessed item
				listItemInnerText = selectItem.Element.GetAttributeValueText("InnerText");
			}
		}
Hope this helps?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

gsb
Posts: 17
Joined: Wed Mar 17, 2021 3:49 pm

Re: How to get and Store list item value from drop down and store into Array variable and then call that value

Post by gsb » Fri Apr 23, 2021 5:18 pm

Thanks for the reply,

/dom[@domain='mydomain.com']//form[#'loanRegisterShort']/tag[1]/?/?/div/?/?/tag[@tagname='row']/div/tag[2]/tag[@tagname='row']/div/?/?/tag[@tagname='ng-component']/div/tag[@tagname='single-select']/div/div[2]/ul/li[7]

Have manual update in OR every time the li[7] value to select required value. If the list keeps increasing had to update list value

Below is latest changes done on xpath with list value is 8
The required value to be selected is the inner text Gurpreet Ubhi (which gets updated)
/dom[@domain='mydomain.com']//form[#'loanRegisterShort']/tag[1]/?/?/div/?/?/tag[@tagname='row']/div/tag[2]/tag[@tagname='row']/div/?/?/tag[@tagname='ng-component']/div/tag[@tagname='single-select']/div/div[2]/ul/li[8]/?/?/span[@innertext='Gurpreet Ubhi']

Instead of manually updating OR what would be approach for selecting the required value ?

gsb
Posts: 17
Joined: Wed Mar 17, 2021 3:49 pm

Re: How to get and Store list item value from drop down and store into Array variable and then call that value

Post by gsb » Fri Apr 23, 2021 5:21 pm

gsb wrote:
Wed Apr 14, 2021 10:20 pm
Now you need to use foreach loop to obtain individual list items and get their innertexts. Ideally, use method with repoInfoElement as a parameter to which you should pass repo element with above xpath...
I am sorry could you please help in this. the list is getting updated every time . not sure how to use the below code

Code: Select all

public void GetListItems(RepoItemInfo selectItemsInfo)
		{
			string listItemInnerText;
			IList <SpanTag> selectItemsList = selectItemsInfo.CreateAdapters<Ranorex.SpanTag>();
			foreach (Ranorex.SpanTag selectItem in selectItemsList)
			{
				//do whatever you want with obtained select item ;)
				//in this case, it will get InnerText of currently accessed item
				listItemInnerText = selectItem.Element.GetAttributeValueText("InnerText");
			}
		}