0

I'm fighting with the following button, trying to assert that it is disabled:

<button _ngcontent-c20 appsymbol="plus" class="btn btn-primary" type="button" disabled>

button.isEnabled() returns true even though it is disabled. I know it is disabled from manually trying to click it, and because it says so in the tag. Does anyone have any idea how I can test that it is actually disabled, or test that the tag contains 'disabled'?

I'm not trying to click the button, rather test that it is disabled because the form it belongs to has not been completed correctly.

1

You are calling is_enabled() on the click() result (None). Instead, you should first get the element, check if it is_enabled() then try the click() (if that is what you are trying to do). For example

elem = driver.find_element_by_id("myId") if elem.is_enabled(): elem.click() else: pass # whatever logic to handle.

  • Thanks for that. I'm not trying to click the button in my test, just show that it is disabled because the form has not been completed correctly. – Shergar Sep 18 '18 at 13:47
  • for that you have to find the element which is showing to complete the form and if it's there then test is fail otherwise it is passed. For example if you have 6 digit pin to enter in a password field and you are entering 4 digit pin then warning comes "pin should be six digits". Then select the warning element and check in test case whether that element is there by entering the incomplete form.If it's not there then test case is passed otherwise fail. – apoorvanand Sep 18 '18 at 14:08
0

I ended up using JSoup (jsoup.org) to check for the presence of the 'disabled' attribute.

  1. Create a JSoup document containing the current page source.
  2. Find the button element in the document.
  3. Assert that the button element contains "disabled".

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.