Hi All,
I need help in selecting a value from the lookup field in Salesforce Community
I have set Text to Test doctor not sure how to select the value Test Doctor that gets displayed in the list. I tried Select by Value, Select by Label but nothing worked.
Send keys, delay for 3 seconds then click the option ?
Select value by label sometimes does not work for me
You need to look at the HTML to see if the “value” attribute has content, such as value=“Test Doctor”, or if the text is displayed outside of an attribute, such as …style>Test Doctor< /p >.
If the value attribute has content, then use: WebUI.selectOptionByValue().
Otherwise, use WebUI.selectOptionByLabel()
The element you show is not a select. The element is a span. (Also, I now notice there is no drop-down indicator on the field). So, you won’t be able to use the selectOptionByLabel nor selectOptionByValue method. You can search the code page to see if there are multiple instances of “Test Doctor” to ensure you have the correct section–maybe there is a select elsewhere.
If you are trying to get the text of the field, then I would try:
String doc = WebUI.getText(findTestObject(‘myPage/span_TreatingPhysician’);
For the object span_TreatingPhysician, you can try the following:
On Chrome, hit F12, then right click and select Inspect. This will bring the code window up like you have above. Click within the code window and hit CTRL + F. Within the search bar that should appear, type: //span[@class=“slds-pill__label”] or type: //span[(text() = ‘Test Doctor’ or . = ‘Test Doctor’)]
To the right of the span xpath should appear 1 of 1. Use whichever xpath gives you the 1 of 1. If neither does, then a better descriptor to the element needs to be found, like id(“lookatme”)/preceding-sibling::div/span/span/span[@class=“slds-pill__label”]
Note if you try copy and paste, you have to change the “smart” quotes (have a curl or curve to them) for straight quotes.
If you are trying to put “Test Doctor” into the field, then you could use:
WebUI.setText(findTestObject(findTestObject(‘myPage/span_TreatingPhysician’, “Test Doctor”)
but I think the element changes from an input to a span after the field is filled (so the above may not work as it wouldn’t be the correct element at the time of data entry).