#NEWLINE# def _get_clickable( clickdata , form ) : #NEWLINE# #INDENT# '\n    Returns the clickable element specified in clickdata,\n    if the latter is given. If not, it returns the first\n    clickable element found\n    ' #NEWLINE# clickables = [ el for el in form . xpath ( 'descendant::*[(self::input or self::button) and re:test(@type, "^submit$", "i")]|descendant::button[not(@type)]' , namespaces = { #NEWLINE# #INDENT# 're' : 'http://exslt.org/regular-expressions' , #NEWLINE# #UNINDENT# } ) ] #NEWLINE# if ( not clickables ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if ( clickdata is None ) : #NEWLINE# #INDENT# el = clickables [ 0 ] #NEWLINE# return ( el . get ( 'name' ) , ( el . get ( 'value' ) or '' ) ) #NEWLINE# #UNINDENT# nr = clickdata . get ( 'nr' , None ) #NEWLINE# if ( nr is not None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# el = list ( form . inputs ) [ nr ] #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( el . get ( 'name' ) , ( el . get ( 'value' ) or '' ) ) #NEWLINE# #UNINDENT# #UNINDENT# xpath = ( './/*' + '' . join ( ( ( '[@%s="%s"]' % c ) for c in six . iteritems ( clickdata ) ) ) ) #NEWLINE# el = form . xpath ( xpath ) #NEWLINE# if ( len ( el ) == 1 ) : #NEWLINE# #INDENT# return ( el [ 0 ] . get ( 'name' ) , ( el [ 0 ] . get ( 'value' ) or '' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( el ) > 1 ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Multiple elements found (%r) matching the criteria in clickdata: %r' % ( el , clickdata ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( ( 'No clickable element matching clickdata: %r' % ( clickdata , ) ) )