{"id":23950,"date":"2020-06-29T11:42:51","date_gmt":"2020-06-29T11:42:51","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=23950"},"modified":"2021-03-06T10:06:46","modified_gmt":"2021-03-06T10:06:46","slug":"how-to-set-value-for-multi-select-attribute-in-dynamics-365-crm-using-xpath-in-easyrepro","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2020\/06\/how-to-set-value-for-multi-select-attribute-in-dynamics-365-crm-using-xpath-in-easyrepro\/","title":{"rendered":"How to set value for Multi-Select attribute in Dynamics 365 CRM using XPath in EasyRepro"},"content":{"rendered":"<p><strong>Introduction<\/strong><\/p>\n<p style=\"text-align: justify;\">Automate Testing can be done in a proficient way in Dynamics 365 CRM through EasyRepro. It covers mass functionalities for support in fields, command bar and much more. As we know, Option Set fields cannot be set like a string field so we use the below syntax to tackle the option set field.<\/p>\n<p><strong>xrmApp.Entity.SetValue (new OptionSet {Name = &#8220;OptionSetLabel&#8221;, Value = \u201cOptionSetValue\u201d});<\/strong><\/p>\n<p>However, we cannot achieve the same thing for multi-select option set field with this way.<\/p>\n<p><strong>Solution<\/strong><\/p>\n<p style=\"text-align: justify;\">We can achieve this with a little knowledge of XPath. \u00a0Consider a multi-select OptionSet field on contact form named as \u201cLanguages\u201d in which you can select the languages your contacts used for their communication.<\/p>\n<p style=\"padding-left: 80px;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-23951\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/1Multi-Select-attribute.png\" alt=\"Multi-Select attribute\" width=\"392\" height=\"241\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/1Multi-Select-attribute.png 392w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/1Multi-Select-attribute-300x184.png 300w\" sizes=\"(max-width: 392px) 100vw, 392px\" \/><\/p>\n<p>Now follow the below steps to select a value in this field.<\/p>\n<p><strong>Step 1: <\/strong><\/p>\n<p style=\"text-align: justify;\">You can choose any value from the field you like, in this example we will select \u201cEnglish\u201d as a language that the contact used for his \/ her communication. We took the value in a variable \u201clanguage\u201d for further use.<\/p>\n<p><strong>var language = \u201cEnglish\u201d;<\/strong><\/p>\n<p><strong>Step 2:<\/strong><\/p>\n<p>We want to add the above value in the input tag of the multi-select field to search the value from the dropdown list.<\/p>\n<p>We will use XPath to find the target input. There are two ways as shown below to get the XPath of the target element.<\/p>\n<p>1. Right Click on the target element and select Inspect.<\/p>\n<p style=\"padding-left: 80px;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-23952\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/2Multi-Select-attribute.png\" alt=\"Multi-Select attribute\" width=\"524\" height=\"376\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/2Multi-Select-attribute.png 524w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/2Multi-Select-attribute-300x215.png 300w\" sizes=\"(max-width: 524px) 100vw, 524px\" \/><\/p>\n<p>2. Dev Tools will open and highlight the target element.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-23953\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/3Multi-Select-attribute.png\" alt=\"Multi-Select attribute\" width=\"1192\" height=\"463\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/3Multi-Select-attribute.png 1192w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/3Multi-Select-attribute-300x117.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/3Multi-Select-attribute-768x298.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/3Multi-Select-attribute-1024x398.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/3Multi-Select-attribute-660x256.png 660w\" sizes=\"(max-width: 1192px) 100vw, 1192px\" \/><\/p>\n<p>3. Now the first way is to right click on the highlighted part and select <strong>Copy &gt; Copy XPath <\/strong>and you will get your XPath for the target element.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-23954\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/4Multi-Select-attribute.png\" alt=\"Multi-Select attribute\" width=\"1122\" height=\"564\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/4Multi-Select-attribute.png 1122w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/4Multi-Select-attribute-300x151.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/4Multi-Select-attribute-768x386.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/4Multi-Select-attribute-1024x515.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/4Multi-Select-attribute-660x332.png 660w\" sizes=\"(max-width: 1122px) 100vw, 1122px\" \/><\/p>\n<p style=\"text-align: justify;\">4. Another way is to create an XPath. As we observe the highlighted part, we can get many attributes of input target. Here we found a unique id, so we will create an XPath consisting of input and its id. To create an XPath, click <strong>CTRL + F <\/strong>on the Dev Tools it will give a textbox on the bottom. Here we will write the XPath, as we know it is an input tag with a unique id named \u201cnew_languages_leedit\u201d. We can write, <strong>\/\/input[@id=&#8217;new_languages_leedit\u2019]. <\/strong>It means to search an input tag with id = \u2018new_languages_leedit\u2019.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-23955\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/5Multi-Select-attribute.png\" alt=\"Multi-Select attribute\" width=\"1102\" height=\"385\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/5Multi-Select-attribute.png 1102w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/5Multi-Select-attribute-300x105.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/5Multi-Select-attribute-768x268.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/5Multi-Select-attribute-1024x358.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/5Multi-Select-attribute-660x231.png 660w\" sizes=\"(max-width: 1102px) 100vw, 1102px\" \/><\/p>\n<p>Also, remember that your target window is the main window, which is the form page.<\/p>\n<p><strong>var xrmBrowser = client.Browser;<\/strong><\/p>\n<p><strong>var win = xrmBrowser.Driver.SwitchTo().Window(xrmBrowser.Driver.CurrentWindowHandle);<\/strong><\/p>\n<p>In <strong>win.FindElement <\/strong>method, use By.XPath to locate the target and store it in a variable.<\/p>\n<p><strong>var languageElement = win.FindElement(By.XPath(&#8220;\/\/input[@id=&#8217;new_languages_leedit &#8216;]&#8221;));<\/strong><\/p>\n<p><strong>Step 3:<\/strong><\/p>\n<p>Input the value in the target element from SendKeys() method.<\/p>\n<p><strong>languageElement.SendKeys(language);<\/strong><\/p>\n<p style=\"padding-left: 80px;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-23956\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/6Multi-Select-attribute.png\" alt=\"Multi-Select attribute\" width=\"383\" height=\"161\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/6Multi-Select-attribute.png 383w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/6Multi-Select-attribute-300x126.png 300w\" sizes=\"(max-width: 383px) 100vw, 383px\" \/><\/p>\n<p>After the input, the result can be seen in above image.<\/p>\n<p><strong>Step 4:<\/strong><\/p>\n<p>Now, we have to select the <strong>\u201cEnglish\u201d <\/strong>label from the dropdown list.<\/p>\n<p style=\"text-align: justify;\">Therefore, we need an XPath to select the dropdown label. Here, we have the dropdown labels with a unique value in its title. Therefore, we should create an XPath consisting of label and its title. Follow the above steps to get the XPath of the label. As shown in the image below we created, it\u2019s XPath as<\/p>\n<p><strong>\/\/label[@title=\u201dEnglish\u201d]. <\/strong><\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-23957\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/7Multi-Select-attribute.png\" alt=\"Multi-Select attribute\" width=\"1091\" height=\"300\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/7Multi-Select-attribute.png 1091w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/7Multi-Select-attribute-300x82.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/7Multi-Select-attribute-768x211.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/7Multi-Select-attribute-1024x282.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/7Multi-Select-attribute-660x181.png 660w\" sizes=\"(max-width: 1091px) 100vw, 1091px\" \/><\/p>\n<p><strong>Step 5:<\/strong><\/p>\n<p>The last step is to click on the target label and set it on the Languages field. To achieve that we use <strong>Click()<\/strong> method as shown in the below line of code.<\/p>\n<p><strong>win.FindElement(By.XPath(&#8220;\/\/label[@title='&#8221; + language + &#8220;&#8216;]&#8221;)).Click();<\/strong><\/p>\n<p style=\"padding-left: 40px;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-23958\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/8Multi-Select-attribute.png\" alt=\"Multi-Select attribute\" width=\"416\" height=\"212\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/8Multi-Select-attribute.png 416w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/8Multi-Select-attribute-300x153.png 300w\" sizes=\"(max-width: 416px) 100vw, 416px\" \/><\/p>\n<p style=\"text-align: justify;\">We can see the output in the above image. We added <strong>language <\/strong>variable in above line of code as a dynamic value to make it generic for other values. Follow the same steps to add more values in the particular field, a generic function to choose these values or multiple values would be a bonus.<\/p>\n<p>Hence, our multi-select value is set on the field!<\/p>\n<p><strong>Conclusion:<\/strong><\/p>\n<p>This guide will help those who need to work with Multi-Select values in Dynamics 365 CRM using <strong>EasyRepro<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Automate Testing can be done in a proficient way in Dynamics 365 CRM through EasyRepro. It covers mass functionalities for support in fields, command bar and much more. As we know, Option Set fields cannot be set like a string field so we use the below syntax to tackle the option set field. xrmApp.Entity.SetValue\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2020\/06\/how-to-set-value-for-multi-select-attribute-in-dynamics-365-crm-using-xpath-in-easyrepro\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":23959,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[16,18,2192],"tags":[],"class_list":["post-23950","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dynamics-365","category-dynamics-365-v9-2","category-easyrepro"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/23950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=23950"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/23950\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/23959"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=23950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=23950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=23950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}