How check whether button is enabled or disabled in Web driver.

12,306 views
Skip to first unread message

SHAILESH

unread,
Jun 7, 2012, 8:13:58 AM6/7/12
to seleniu...@googlegroups.com

Hi,

 

I am automating Website in which I have to Test whether button is enabled or disabled.


Which command shall I use?


I am new to Web driver.

 

Thanks and Regards,

Shailesh Jagtap.

Shaba K

unread,
Jun 7, 2012, 8:20:08 AM6/7/12
to seleniu...@googlegroups.com
webelement <somename> = driver.FindElement(By.Xpath());
somename.enabled();
somename.disabled();

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/o9WcNyUHUJoJ.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

SHAILESH

unread,
Jun 11, 2012, 2:47:18 AM6/11/12
to seleniu...@googlegroups.com
Thank You Shaba!


On Thursday, June 7, 2012 5:50:08 PM UTC+5:30, Shaba wrote:
webelement <somename> = driver.FindElement(By.Xpath());
somename.enabled();
somename.disabled();

On Thu, Jun 7, 2012 at 1:13 PM, SHAILESH <shailesh.jagtap@encodexindia.com> wrote:

Hi,

 

I am automating Website in which I have to Test whether button is enabled or disabled.


Which command shall I use?


I am new to Web driver.

 

Thanks and Regards,

Shailesh Jagtap.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/o9WcNyUHUJoJ.
To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

Dinesh s

unread,
Jun 11, 2012, 6:15:05 AM6/11/12
to seleniu...@googlegroups.com
Hi
may be it is useful
WebElement button= driver.findElement(By.id("id"));
        if(button.isEnabled())
        {
        d.findElement(By.id("id")).click();
        System.out.println("the button is enabled");
        }
        else
        {
            System.out.println("the button is disabled");
        }

SH

unread,
Jun 13, 2012, 8:00:57 AM6/13/12
to seleniu...@googlegroups.com

Hi,

 

I used your method to check element enabled/disable in C#.

 

It does not show webelement as class.

 

My Directives in code -

using System;

using System.Collections.Generic;

using System.Text;

using System.Text.RegularExpressions;

using System.Threading;

using NUnit.Framework;

using OpenQA.Selenium;

using OpenQA.Selenium.Firefox;

using OpenQA.Selenium.Support.UI;

 

I am using "selenium-dotnet-2.12.0" - net40.

 

Please Help me!

 

Thanks,

Shailesh

SH

unread,
Jun 20, 2012, 7:30:10 AM6/20/12
to seleniu...@googlegroups.com
Answer to my above Question is-

Return type of FindElement in C# is IWebElement.

You can get the button (or any element)

IWebElement element = driver.FindElement(By.XPath("")); 

After getting the element, you can check the property 'Enabled' which is a boolean.

It can be access like 
bool buttonEnabled = element.Enabled; 

Regards,
Shailesh.

Jayanath karunarathna

unread,
May 8, 2014, 4:44:03 AM5/8/14
to seleniu...@googlegroups.com
Hi Dinesh,
 I think this is not a good practice as we are performing a unwanted click. I see 2 problems here
  1. If the element is disabled we get UnknownError(Element is not clickable at this poit) instead of assertion Error
  2. If the element is enabled selenium will perform click action and most probably navigate to another page.

Therefore My opinion is checking whether button is enabled should be enough.
  Assert.assertFalse("Button should be disabled!", button.isEnabled() );

On Monday, June 11, 2012 3:45:05 PM UTC+5:30, Dinesh wrote:
Reply all
Reply to author
Forward
0 new messages