0

Every implementation of Get Locator keyword I am trying is resulting into:

AttributeError: 'dict' object has no attribute 'format'`

please educate me with respect to the correct implementation and use of this keyword.

Background: I have a VF page, it has an iframe on which there is a modal with few fields. I need to populate this modal and save to create a new record.

Issue: Neither Wait Until Modal Is Open nor Populate Field keywords are working on this modal. Reason being the default Cci modal locator strategy fails and throws:

Element 'css: div.uiModal div.panel.slds-modal' did not appear in 15 seconds

Workaround: I have to traverse this modal and its fields using Selenium and then populate it. I am hating every bit of it and feel that i am falling short of understanding the Cci and Salesforce locator keywords and hence want to learn their implementation. I have similar screens at other places in my app too, so I know this is going to come handy.

*** TestCases ***
Verify user can Add New Objective At Impact Level
    Click Element  ${AddNewFrameworkItemButton}
    ###Below Cci keywords are unable to detect the modal and hence are falling short 
    #Wait Until Modal Is Open  # bcoz my modal is not detected, i use Get Locator next
    #Get Locator  object  field=Add New Framework Item    
    #Populate Field  Objective Name  TA_P1_Obj1
    #Populate Field  Definition  This is a Level 1 Objective
    #Populate Field  Level  Impact
    #Populate Lookup Field  Parent Objective  L1 Objective
    #Click Modal Button  Save
    ###As a workaround, I need to use Selenium stuff
    Click Element  ${AddNewFrameworkItemButton}
    Wait Until Page Contains Element  ${AddNewObjectiveHeader}
    Input Text  ${ObjectiveNameTextArea}  TA_P1_Obj1
    Input Text  ${DefinitionTextArea}  This is a Level 1 Objective
    .....

Need guidance on how I can use Get Locator keyword to identify VF modals and then use Cci keywords to populate forms.

1

Answered suggested by Bryan Oakley

please educate me with respect to the correct implementation and use of this keyword.

The Salesforce keyword library has a data structure called lex_locators. It is nothing more than a dictionary of keys and values. Values are either strings or nested dictionaries. The strings are often format strings that take additional arguments.

The path argument given to get locators is just a dot-separated string representing this structure.

For example, part of this structure looks like this:

lex_locators = {
    ...,
    "modal": {
        "button": "//div[contains(@class,'uiModal')]//div[contains(@class,'modal-footer')]//button[.//span[text()='{}']]",
        "close": "css: button.slds-modal__close",
        "error_messages": "css: div.pageLevelErrors ul.errorsList li",
        "fade_in": "css: div.slds-fade-in-open",
        "has_error": "css: div.pageLevelErrors",
        "is_open": "css: div.uiModal div.panel.slds-modal",
    },
    ...
}

Notice that the modal "button" locator includes //span[text()='{}'. The {} is a placeholder for text, which will be replaced by calling python's format method. The text must be supplied when calling get locator.

Continuing with the example, to get the locator for a modal dialog button with the text "Save", you would do it like this:

${locator}=  Get locator  modal.button  Save

When you run the above code it will return this string:

//div[contains(@class,'uiModal')]//div[contains(@class,'modal footer')]//button[.//span[text()='Save']]

Need guidance on how I can use Get Locator keyword to identify VF modals and then use Cci keywords to populate forms.

I don't think Get Locator is going to help you. Get Locator is for getting a standard locator used by the other Salesforce keywords. Your problem is that your UI element appears to be using a non-standard locator. You can't force the Salesforce library keywords to use a non-standard locator unless you modify the standard lex_locators dictionary (which would then break the keywords that work on standard page elements.

If your page uses components that the Salesforce keywords can't see, you'll need to fall back on the selenium library keywords where you provide the locator that works with your page.

In other words, Get Locators lets you use standard locators in non-standard ways, it doesn't let you use non-standard locators in standard ways.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.