First of all, you have to ensure that backend configuration settings don't make the same screen look different in various environments if you want to refer to screen objects in your script.
For the above situation, you'll have to make sure your script first expands the container if it is collapsed, before using any screen elements that are part of that collapsible container. Essentially you'll have to query whether the control exists on the screen (there is an appropriate script action for this), and if it is not, then it can be assumed that currently the container is collapsed. So first you'd have to click on the "Expand" icon to make the necessary screen object to appear.