0

Test Case

In My web page, I have 5 tabs (A,B,C,D,E) in which 2 tabs (A,B) are clickable and 3 Tabs(C,D,E) are not clickable.

Write a script to verify those tab elements are clickable or not.

What I've tried

1) expect(element(by.id(ID_of_UnCLICKABLE_menu)).isEnabled()).toBe(True); expect(element(by.id(ID_of_CLICKABLE_menu)).isEnabled()).toBe(True);

 Test passed for both unclickable and clickable elements. 
 **ExpectedResult** -> Need to fail for either of one.

and:

2) var EC = protractor.ExpectedConditions;
   browser.driver.wait(EC.elementToBeClickable(element(by.id())), 5000, 'Not Clickable');

HTML code:

<tr>
    <td id="id1234" class="name_style-button disabled" role='menuitem'>Text</td>
</tr> 

Note: This is a non-Angular page.

  • What is TorF in your first try? How does it fail in your first try? Thanks. – alecxe Aug 31 '17 at 14:42
  • Sorry for shorthand type. its True or False. Edited the description. – keasav rao Sep 1 '17 at 6:29
  • As you said. Test should fail for either of one. If so we can differentiate between clickable and non clickable elements. – keasav rao Sep 1 '17 at 6:36
  • I think in this case you would have to check against the class attribute, since that is what your application is using to manipulate that element. In addition, you would have to actually click it and also assert that clicking it does nothing or does something depending on what you expect. The html appears to show them as enabled even though your application, and the way they are displayed, has them disabled, so you can't check it through selenium through those conditions. – mrfreester Sep 1 '17 at 16:52
  • Try using elementToBeClickable() – DrZoo Sep 2 '17 at 6:02
1

First all, how should awnser if the tab is clickable or not? The tab itself.

So, in the tab page object, you should have a function like this:

function isClickable() {
   return this.getAttribute('class').contains('disable');
}

With this, in your test, you can get each tab and test it:

expect(tabA.isClickable().toBe(True));
...
expect(tabE.isClickable().toBe(False));

If you pass the locator for each tab into the Tab page object, it can be used for all tabs. This way, when the way the tabs get disabled change, you will need to change only the isClickable function.

  • You're welcome Keasav. Could you mark the answer as accepted? – João Farias Sep 6 '17 at 16:38
  • 1
    Done.. The difference in html for Clickable and nonclickable was presence of Class=Disable for non clickable. So i written a code as Presence of xpath(class=disabled).toBe(true). Thanks – keasav rao Sep 7 '17 at 6:29

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.