3

I have a problem how to check if the button is disabled. If button is disabled and I use

Assert.IsTrue(driver.FindElement(By.XPath(OKButton)).Enabled, "OK button is disabled.");

it is not finds that button is disabled.

If same button is enabled and I use

Assert.IsFalse(driver.FindElement(By.XPath(OKButton)).Enabled, "OK button is enabled.");

it is finds that button is enabled.

Here is a code for disabled button:

<div id="expBtnOK" class="dxbButton_MetropolisBlue button btn-primaryOk dxbButtonSys dxbTSys dxbDisabled_MetropolisBlue" style="width:80px;-moz-user-select:none;">
<div id="expBtnOK_CD" class="dxb">
<input class="dxb-hb" value="OK" name="expBtnOK" disabled="" type="button"/>
<span class="dx-vam">OK</span>
</div>
</div>
<script id="dxss_381722429" type="text/javascript"> <!-- aspxAddHoverItems('expBtnOK',[[['dxbButtonHover_MetropolisBlue'],[''],[''],['','TC']]]); aspxAddPressedItems('expBtnOK',[[['dxbButtonPressed_MetropolisBlue'],[''],[''],['','TC']]]); aspxAddDisabledItems('expBtnOK',[[['dxbDisabled_MetropolisBlue'],[''],[''],['','TC']]]); var dxo = new MVCxClientButton('expBtnOK'); window['expBtnOK'] = dxo; dxo.Click.AddHandler(ExportTo); aspxAddSelectedItems('expBtnOK',[[['dxbf'],[''],['CD']]]); dxo.useSubmitBehavior = false; dxo.AfterCreate(); //--> </script>

And a code for enabled button:

<div id="expBtnOK" class="dxbButton_MetropolisBlue button btn-primaryOk dxbButtonSys dxbTSys dxbButtonHover_MetropolisBlue" style="width:80px;-moz-user-select:none;">
<div id="expBtnOK_CD" class="dxb">
<input class="dxb-hb" value="OK" name="expBtnOK" type="button"/>
<span class="dx-vam">OK</span>
</div>
</div>
<script id="dxss_381722429" type="text/javascript"> <!-- aspxAddHoverItems('expBtnOK',[[['dxbButtonHover_MetropolisBlue'],[''],[''],['','TC']]]); aspxAddPressedItems('expBtnOK',[[['dxbButtonPressed_MetropolisBlue'],[''],[''],['','TC']]]); aspxAddDisabledItems('expBtnOK',[[['dxbDisabled_MetropolisBlue'],[''],[''],['','TC']]]); var dxo = new MVCxClientButton('expBtnOK'); window['expBtnOK'] = dxo; dxo.Click.AddHandler(ExportTo); aspxAddSelectedItems('expBtnOK',[[['dxbf'],[''],['CD']]]); dxo.useSubmitBehavior = false; dxo.AfterCreate(); //--> </script>

Thanks in advance for your help.

  • Did you solve the problem, can you add an answer with the solution? – Niels van Reijmersdal Aug 19 '18 at 17:23
2

Maybe you shouldn't check the button is disabled, but when you click it the state of the application does not change.

Because checking if it is enabled means you're verifying implementation details. What happens if the programmers change the way how buttons are unclickable, the tests will fail.

It can look unclickable, it can not fire an event when you click, but it can still be enabled.

I would check the workflow is correct. Click the submit button and notice the browser is still on the submit form page and not the next step.

| improve this answer | |
-1

Instead of Assert, you should use isEnabled() function

This has been very well explained HERE and on StackOverflow

| improve this answer | |
-1

You can use the simplest method for Verify enable and disable button in Selenium web driver c#

IwebElement e1 = driver.FindElement(By.XPath("Your Xpath"));

//verify the button's Enabled property

if (e1.Enabled)
Console.WriteLine("Button is enabled");
else
Console.WriteLine("Button is disabled");
| improve this answer | |
  • Isnt the OP already doing that? Seems his issue is the .Enabled property is not working as expected. :) – Niels van Reijmersdal Aug 19 '18 at 17:21

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.