Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test if a field is enabled #32

Closed
rinou92 opened this issue Oct 3, 2017 · 6 comments
Closed

Test if a field is enabled #32

rinou92 opened this issue Oct 3, 2017 · 6 comments

Comments

@rinou92
Copy link

rinou92 commented Oct 3, 2017

Hi,

I'm currently playing with the API and it's very nice, but I haven't found how to test if a field is enabled.
May be I missed something, but if not, it would be nice to have this possibility :-)

@dtu11
Copy link
Member

dtu11 commented Oct 5, 2017

This is something we don't have a specific API for currently but can access the enabled attribute on the element. You can use the xrmBrowser.Document.getElementById("firstname").GetAttribute("disabled"); try get the details.

@troyyer
Copy link

troyyer commented Oct 11, 2017

Sorry but could you provide some more help with this. When I tried grabbing a field with

var FName = xrmBrowser.Document.getElementById("firstname")

I can see the full element in the watcher. However if I try

var FNameDisplay = xrmBrowser.Document.getElementById("firstname").GetAttribute("disabled");
or
var FNameDisplay = xrmBrowser.Document.getElementById("firstname").GetAttribute("Displayed");
it comes up as null in the watcher. What am I doing wrong?

@dtu11
Copy link
Member

dtu11 commented Oct 11, 2017

Ok, it looks like there will be a span that has a lock image. The disabled setting is never set. Try something like this.
if (xrmBrowser.Document.getElementById("firstname_lock").GetAttribute("style") == "display: block;")
{
//do something
}

@dtu11
Copy link
Member

dtu11 commented Oct 11, 2017

You can also execute client script that will get the control disabled status.

xrmBrowser.Driver.ExecuteScript("Xrm.Page.ui.controls.get('firstname').getDisabled();").ToString();

That should return True or False.

@dtu11 dtu11 closed this as completed Oct 11, 2017
@troyyer
Copy link

troyyer commented Oct 11, 2017

So I was still getting an error with
xrmBrowser.Driver.ExecuteScript("Xrm.Page.ui.controls.get('firstname').getDisabled();").ToString();
I was getting a NullReferenceException

We ended up realising it was already present in the IWebElement properties.....
var FNameDisplay = xrmBrowser.Document.getElementById("firstname").Displayed

@mariokrajmer
Copy link

this actually works
xrmBrowser.Driver.ExecuteScript($"return Xrm.Page.getControl('firstname').getDisabled();");

so the previous
xrmBrowser.Driver.ExecuteScript("Xrm.Page.ui.controls.get('firstname').getDisabled();").ToString();
was missing the "return"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants