Reputation: 1
In Sales force application. All the elements doesn't have proper and static id or name or other properties.
My requirement is to get all the values from a dropdownlist on salesforce web-app.
CSS showing on inspecting dropdownlist on chrome browser:
<div data-aura-rendered-by="9529:0"><a aria-required="false" class="select" aria-disabled="false" aria-describedby="9520:0-label" aria-haspopup="true" tabindex="0" role="button" title="" data-aura-rendered-by="9530:0" href="javascript:void(0);" data-interactive-lib-uid="10">--None--</a></div>'
It is only showing already selected value . i.e. None by default in my application.
I am not able to see the other options in this div.This doesn't help me to get values. On inspecting the values inside the dropdown list, it is showing html on some other location
<div class="select-options" role="menu" data-aura-rendered-by="9542:0"><!--render facet: 9543:0--><ul class="scrollable" role="presentation" data-aura-rendered-by="9544:0"><!--render facet: 10751:0--><li role="presentation" data-aura-rendered-by="10755:0" class="uiMenuItem uiRadioMenuItem" data-aura-class="uiMenuItem uiRadioMenuItem"><a data-aura-rendered-by="10756:0" href="javascript:void(0);" role="menuitemradio" aria-disabled="false" tabindex="0" title="--None--" aria-checked="false"><b></b>--None--</a></li><li role="presentation" data-aura-rendered-by="10761:0" class="uiMenuItem uiRadioMenuItem" data-aura-class="uiMenuItem uiRadioMenuItem"><a data-aura-rendered-by="10762:0" href="javascript:void(0);" role="menuitemradio" aria-disabled="false" tabindex="0" title="Provider Concern / Question" aria-checked="false"><b></b>Provider Concern / Question</a></li><li role="presentation" data-aura-rendered-by="10767:0" class="uiMenuItem uiRadioMenuItem" data-aura-class="uiMenuItem uiRadioMenuItem"><a data-aura-rendered-by="10768:0" href="javascript:void(0);" role="menuitemradio" aria-disabled="false" tabindex="0" title="Provider No Show" aria-checked="false"><b></b>Provider No Show</a></li></ul></div>
I tried to use the below code to retrieve values. but only getting empty values:
List<WebElement> subStatuses = driver.findElements(By.xpath("(.//div[@class='select-options popupTargetContainer uiPopupTarget uiMenuList uiMenuList--default uiMenuList--left uiMenuList--short'])[3]//li"));
System.out.println("size of the data list :: "+subStatuses.size()+"values:: "+subStatuses.toString());
for(WebElement e:subStatuses)
{
System.out.println("Values from Fsl dropdownlist"+e.getText().toString());
}
Any help on how to retrieve values from this drop down is appreciated..!
Upvotes: 0
Views: 1578
Reputation: 11
Your xpath seems to be wrong: Try something like that:
List<WebElement> subStatuses = driver.findElements(By.xpath("//div[@class='select-options']/ul/li[contains(@class, 'uiMenuItem')]/a"));
That should work if it's the only "select" on your page. If there is more than one you might need to specify which select-options-div in the dom you want e.g. selecting the first occurrence: //div[@class='select-options'][1]/ul/li[contains(@class, 'uiMenuItem')]/a
and instead of getText(); you might have to use element.getAttribute('textContent');
Upvotes: 1