1

I need to check whether a link's disabled attribute is set, in the following code,

<a id="ctl00_ContentPlaceHolder1_lbtnNext" disabled="disabled">Next</a>

However on the last page if I execute,

next_pg=driver.find_element_by_xpath("//a[@id='ctl00_ContentPlaceHolder1_lbtnNext']")
next_pg.click()
print next_pg.is_enabled()

I get True as the output, which should not be the case. Also, only on the last page is the Next coded as given above, in all other pages it is coded as follows, due to which on checking the is_enabled() tag, an error is produced.

<a id="ctl00_ContentPlaceHolder1_lbtnNext" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$lbtnNext','')">

How should I solve this?

n00b
  • 1,549
  • 2
  • 14
  • 33

1 Answers1

0

Use this answer to get the attributes of the tag:

attrs = driver.execute_script('var items = {}; for (index = 0; index < arguments[0].attributes.length; ++index) { items[arguments[0].attributes[index].name] = arguments[0].attributes[index].value }; return items;', next_pg)

and check for the presence of the disabled tag and it's value:

if 'disabled' in attrs and attrs['disabled'] == 'disabled':
    # ...
Community
  • 1
  • 1
Celeo
  • 5,583
  • 8
  • 39
  • 41