@@ -766,6 +766,46 @@ def process_command(self, command):
766766 self .devtools .type_text (command ['target' ])
767767 elif command ['command' ] == 'keypress' :
768768 self .devtools .keypress (command ['target' ])
769+ elif command ['command' ] == 'mouseclick' :
770+ if 'target' in command :
771+ target = command ['target' ]
772+ separator = target .find ('=' )
773+ if separator == - 1 :
774+ separator = target .find ("'" )
775+ if separator >= 0 :
776+ attribute = target [:separator ]
777+ attr_value = target [separator + 1 :]
778+ mouseclickError = False
779+ try :
780+ query = "JSON.stringify(document.querySelector('[{0}=\" {1}\" ]').getBoundingClientRect())" .format (
781+ attribute , attr_value )
782+ resp = self .devtools .execute_js (query , use_execution_context = True )
783+ resp_json = json .loads (resp )
784+
785+ value = command ['value' ]
786+ button = 'left'
787+ clickCount = 1
788+ if value in ['left' , 'right' ]:
789+ button = value
790+ elif value == 'double' :
791+ clickCount = 2
792+ elif value is not None :
793+ logging .info ("Click type is not defined." )
794+ mouseclickError = True
795+
796+ if 'x' in resp_json and 'y' in resp_json and 'width' in resp_json and 'height' in resp_json :
797+ x = int (float (resp_json ['x' ])) + int (float (resp_json ['width' ]))/ 2
798+ y = int (float (resp_json ['y' ])) + int (float (resp_json ['height' ]))/ 2
799+ commandOptions = {}
800+ commandOptions ['x' ] = x
801+ commandOptions ['y' ] = y
802+ commandOptions ['button' ] = button
803+ commandOptions ['clickCount' ] = clickCount
804+ self .devtools .mouseClick (commandOptions )
805+ except :
806+ self .task ['error' ] = 'Exception parsing mouseClick arguments.'
807+ logging .error (self .task ['error' ])
808+ mouseclickError = True
769809 elif command ['command' ] == 'waitfor' :
770810 try :
771811 self .devtools .wait_for_script = command ['target' ] if command ['target' ] else None
0 commit comments