Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have searched the forums before posting this issue here. I have found some answers but i am not able to get the success from the answers in that. My issue is

How to check the link is enabled in Webdriver using java. Please find the attached screen shots for the same.

enter image description here

enter image description here

I have written the code for this:

WebElement textlink = driver.findElement(By.id(OR.getProperty("lnkView_ID")));
if (textlink.isEnabled())
   System.out.println("View link: Enabled");
else
   System.out.println("View link: Disabled");

Please help me out with this issue. Help will be appreciated.

share|improve this question
 
What's the error reported? –  Abhijeet Vaikar Aug 7 at 13:15
 
Also, what is the actual locator you are using for locating the link? Can you mention that too? –  Abhijeet Vaikar Aug 7 at 13:24
1  
I'd recommend double-checking that ID you're using. Is it definitely unique and constant; it doesn't change each time you load the page, or refresh the list of actions does it? Also, have you definitely got it preset in your script? Apart from that, your code looks like it's trying to do the right thing. –  vincebowdren Aug 7 at 13:26
 
Thanks for the reply. I am not getting any error but its printing Enabled message even it is disabled. I am using the ID property for locating the link. id = ctl00_MasterPlaceHolder_grdAppln_ctl02_lnkView –  Umamaheshwar Thota Aug 7 at 13:27
 
In the ID property, on the number ctl02 will change when the new row is added. but i want it for the same row with ctl00_MasterPlaceHolder_grdAppln_ctl02_lnkView. Because, i will create new Applicant every time for different users when i run it. So the id property will be the same for all. –  Umamaheshwar Thota Aug 7 at 13:32

2 Answers

up vote 1 down vote accepted

Try the following:

String isDisabled = textlink.getAttribute("disabled");
if (isDisabled==null || !isDisabled.equals("disabled")){
   System.out.println("View link: Enabled");
}else{
   System.out.println("View link: Disabled");
}

It looks like the attribute "disabled" is the toggle for whether it is enabled or not, so you can check for it using getAttribute();

share|improve this answer
 
Sorry for delayed answer. It worked for me. Thanks –  Umamaheshwar Thota Aug 14 at 10:51

Check for the attribute disabled in tag. As 'View' link is disabled and you can find from your HTML that its represented by disabled="disabled". Write an identifier in XPath for or use Id identifier and like below find the link status using the attribute value for disabled.

string viewLinkXpath = "//tobody/tr/td/a";
IWebElement viewLinkElement = driver.FindElement(By.XPath(viewLinkXpath));
if(viewLinkElement.GetAttribute("disabled")!="disabled")
{
   Console.WriteLine("View link enabled");
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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