Skip to content

keyboard_mouse_actions

KeyboardMouseActions

Description

| This class contains methods related to ActionChains Class of Selenium package.

Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
class KeyboardMouseActions:
    """
    Description:
        |  This class contains methods related to ActionChains Class of Selenium package.
    """

    def __init__(self, web_driver: webdriver.Remote = None, default_explicit_wait: int = None):
        """Initializes KeyboardMouseActions with a driver and optional explicit
        wait.

        Args:
            web_driver: The selenium webdriver instance.
                            if not provided, it will be picked from Session Store
            default_explicit_wait: The default explicit wait time (in seconds).
                                   If not provided, it will be retrieved from ConfigUtils.
        """
        self.default_explicit_wait = default_explicit_wait or ConfigUtils().get_explicit_wait()
        self.logger = CoreLogger(name=__name__).get_logger()
        self.driver = web_driver or SessionStore().storage.get("driver")
        self.actions = ActionChains(self.driver)
        self.wca = WebClientActions(
            self.driver, default_explicit_wait=self.default_explicit_wait, default_implicit_wait=5
        )

    def robust_click(self, locator: Union[str, WebElement], explicit_wait: int = None) -> None:
        """Click on the locator provided.It will find the element for the
        locator given, convert it into a web element then wait for it to be
        clickable. The time of wait will depend on the value passed in the
        explicit wait.

        Examples:
            >> from cafex_ui import CafeXWeb
            >> CafeXWeb().robust_click("xpath=//a[@class='advanced-search-link']")
            >> CafeXWeb().robust_click("xpath=//a[@class='advanced-search-link']", 30)

        Args:
            locator: A string representing the locator in a fixed format which is, locator_type=locator/web_element.
                     For example: id=username or xpath=.//*[@id='username'] or web_element
            explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

        Returns:
            None
        """
        try:
            explicit_wait = explicit_wait or self.default_explicit_wait
            self.wca.get_clickable_web_element(locator, explicit_wait).click()
        except Exception:
            try:
                self.actions.click(
                    self.wca.get_clickable_web_element(locator, explicit_wait)
                ).perform()
            except Exception:
                try:
                    self.wca.execute_javascript(
                        "arguments[0].click();",
                        self.wca.get_clickable_web_element(locator, explicit_wait),
                    )
                except Exception as e3:
                    self.logger.exception(
                        "Exception in robust_click method. Exception Details:", exc_info=e3
                    )
                    raise e3

    def right_click(
            self, locator: Union[str, WebElement] = None, explicit_wait: int = None
    ) -> None:
        """Perform right click operation on the locator / web element which
        user passes. If element/locator is not being passed, right click
        operation gets performed on where cursor point is.

        Examples:
            >> from cafex_ui import CafeXWeb
            >> CafeXWeb().right_click()
            >> CafeXWeb().right_click("xpath=//div[@id='context-menu']")
            >> CafeXWeb().right_click("xpath=//div[@id='context-menu']", 30)

        Args:
            locator: A string representing the locator in a fixed format which is, locator_type=locator.
                     For example: id=username or xpath=.//*[@id='username'] or web_element
            explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

        Returns:
            None
        """
        try:
            explicit_wait = explicit_wait or self.default_explicit_wait
            if locator is not None:
                self.actions.context_click(
                    self.wca.get_clickable_web_element(locator, explicit_wait)
                ).perform()
            else:
                self.actions.context_click().perform()
        except Exception as e:
            self.logger.exception("Exception in right_click method.Exception Details: %s", str(e))
            raise e

    def double_click(
            self, locator: Union[str, WebElement] = None, explicit_wait: int = None
    ) -> None:
        """Perform double click operation on the locator / web element which
        user passes. If element/locator is not being passed, double click
        operation gets performed on where cursor point is.

        Examples:
            >> from cafex_ui import CafeXWeb
            >> CafeXWeb().double_click()
            >> CafeXWeb().double_click("xpath=//button[@id='double-click']")
            >> CafeXWeb().double_click("xpath=//button[@id='double-click']", 30)

        Args:
            locator: A string representing the locator in a fixed format which is, locator_type=locator.
                     For example: id=username or xpath=.//*[@id='username'] or web_element
            explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

        Returns:
            None
        """
        try:
            explicit_wait = explicit_wait or self.default_explicit_wait
            if locator is not None:
                self.actions.double_click(
                    self.wca.get_clickable_web_element(locator, explicit_wait)
                ).perform()
            else:
                self.actions.double_click().perform()
        except Exception as e:
            self.logger.exception("Exception in double_click method.Exception Details: %s", str(e))
            raise e

    def drag_and_drop(
            self,
            source_element: Union[str, WebElement],
            target_element: Union[str, WebElement],
            explicit_wait: int = None,
    ) -> None:
        """Drag source element and drop source element to the target element.

        Examples:
            >> from cafex_ui import CafeXWeb
            >> CafeXWeb().drag_and_drop("xpath=//div[@id='source']", "xpath=//div[@id='target']")
            >> CafeXWeb().drag_and_drop("xpath=//div[@id='source']", "xpath=//div[@id='target']", 30)

        Args:
            source_element: A string representing the locator in a fixed format which is, locator_type=locator.
                            For example: id=username or xpath=.//*[@id='username'],or web_element
            target_element: A string representing the locator in a fixed format which is, locator_type=locator.
                            For example: id=username or xpath=.//*[@id='username'],or web_element
            explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

        Returns:
            None
        """
        try:
            explicit_wait = explicit_wait or self.default_explicit_wait
            self.actions.drag_and_drop(
                self.wca.get_web_element(source_element, explicit_wait=explicit_wait),
                self.wca.get_web_element(target_element, explicit_wait=explicit_wait),
            ).perform()
        except Exception as e:
            self.logger.exception("Exception in drag_and_drop method.Exception Details: %s", str(e))
            raise e

    def drag_and_drop_by_offset(
            self,
            source_element: Union[str, WebElement],
            x_offset: int,
            y_offset: int,
            explicit_wait: int = None,
    ) -> None:
        """Hold down the left mouse button on the source element, then move to
        the target offset and release the mouse button.

        Examples:
            >> from cafex_ui import CafeXWeb
            >> CafeXWeb().drag_and_drop_by_offset("xpath=//div[@id='source']", 100, 200)
            >> CafeXWeb().drag_and_drop_by_offset("xpath=//div[@id='source']", 100, 200, 30)

        Args:
            source_element: A string representing the locator in a fixed format which is, locator_type=locator.
                    For example: id=username or xpath=.//*[@id='username'] or web_element
            x_offset: X offset to move to.
            y_offset: Y offset to move to.
            explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

        Returns:
            None
        """
        try:
            explicit_wait = explicit_wait or self.default_explicit_wait
            self.actions.drag_and_drop_by_offset(
                self.wca.get_web_element(source_element, explicit_wait), x_offset, y_offset
            ).perform()
        except Exception as e:
            self.logger.exception(
                "Exception in drag_and_drop_by_offset method.Exception Details: %s", str(e)
            )
            raise e

    def move_to_element(
            self, locator: Union[str, WebElement], then_click: bool = False, explicit_wait: int = None
    ) -> None:
        """Move the mouse cursor to the web element or the locator the cursor
        needs to move to.

        Examples:
            >> from cafex_ui import CafeXWeb
            >> CafeXWeb().move_to_element("xpath=//div[@id='element']")
            >> CafeXWeb().move_to_element("xpath=//div[@id='element']", 30)

        Args:
            locator: A string representing the locator in a fixed format which is, locator_type=locator.
                     For example: id=username or xpath=.//*[@id='username'] or web_element
            then_click: A boolean representing whether to click after moving to the element.
            explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

        Returns:
            None
        """
        try:
            explicit_wait = explicit_wait or self.default_explicit_wait
            if then_click:
                self.actions.move_to_element(
                    self.wca.get_clickable_web_element(locator, explicit_wait)
                ).click()
            else:
                self.actions.move_to_element(
                    self.wca.get_clickable_web_element(locator, explicit_wait)
                ).perform()
        except Exception as e:
            self.logger.exception(
                "Exception in move_to_element method.Exception Details: %s", str(e)
            )
            raise e

    def control_click(self, locator: Union[str, WebElement], explicit_wait: int = None) -> None:
        """Perform control click operation on given web element and the element
        would be opened in new window.

        Examples:
            >> from cafex_ui import CafeXWeb
            >> CafeXWeb().control_click("xpath=//a[@id='link']")
            >> CafeXWeb().control_click("xpath=//a[@id='link']", 30)

        Args:
            locator: A string representing the locator in a fixed format which is, locator_type=locator.
                     For example: id=username or xpath=.//*[@id='username'] or web_element
            explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

        Returns:
            None
        """
        try:
            explicit_wait = explicit_wait or self.default_explicit_wait
            self.actions.key_down(keys.Keys.CONTROL).click(
                self.wca.get_web_element(locator, explicit_wait=explicit_wait)
            ).key_up(keys.Keys.CONTROL).perform()
        except Exception as e:
            self.logger.exception("Exception in control_click method.Exception Details: %s", str(e))
            raise e

    def release(self, key: str = None) -> None:
        """Release all the keys which are pressed.If single key specified, it
        releases that key.

        Examples:
            >> from cafex_ui import CafeXWeb
            >> CafeXWeb().release()
            >> CafeXWeb().release(keys.Keys.CONTROL)

        Args:
            key: A key which needs to be released.

        Returns:
            None
        """
        try:
            if key is not None:
                self.actions.key_up(key).perform()
            else:
                self.actions.release().perform()
        except Exception as e:
            self.logger.exception("Exception in release method.Exception Details: %s", str(e))
            raise e

    def move_to_element_with_offset(
            self,
            locator: Union[str, WebElement],
            x_offset: int,
            y_offset: int,
            explicit_wait: int = None,
    ) -> None:
        """Move the mouse cursor to the web element or the locator the cursor
        needs to move to.

        Examples:
            >> from cafex_ui import CafeXWeb
            >> CafeXWeb().move_to_element_by_offset("xpath=//div[@id='element']", 100, 200)
            >> CafeXWeb().move_to_element_by_offset("xpath=//div[@id='element']", 100, 200, 30)

        Args:
            locator: A string representing the locator in a fixed format which is, locator_type=locator.
                     For example: id=username or xpath=.//*[@id='username'] or web_element
            x_offset: X offset to move to.
            y_offset: Y offset to move to.
            explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

        Returns:
            None
        """
        try:
            explicit_wait = explicit_wait or self.default_explicit_wait
            self.actions.move_to_element_with_offset(
                self.wca.get_clickable_web_element(locator, explicit_wait), x_offset, y_offset
            ).perform()
        except Exception as e:
            self.logger.exception(
                "Exception in move_to_element_by_offset method.Exception Details: %s", str(e)
            )
            raise e

    def click_and_hold(self, locator: [str, WebElement], explicit_wait: int = None) -> None:
        """Perform click and hold operation on the locator / web element which
        user passes.

        Examples:
            >> from cafex_ui import CafeXWeb
            >> CafeXWeb().click_and_hold("xpath=//div[@id='element']")
            >> CafeXWeb().click_and_hold("xpath=//div[@id='element']", 30)

        Args:
            locator: A string representing the locator in a fixed format which is, locator_type=locator.
                     For example: id=username or xpath=.//*[@id='username'] or web_element
            explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

        Returns:
            None
        """
        try:
            explicit_wait = explicit_wait or self.default_explicit_wait
            self.actions.click_and_hold(
                self.wca.get_clickable_web_element(locator, explicit_wait)
            ).perform()
        except Exception as e:
            self.logger.exception(
                "Exception in click_and_hold method.Exception Details: %s", str(e)
            )
            raise e

    def reset_actions(self) -> None:
        """Reset the actions.

        Examples:
            >> from cafex_ui import CafeXWeb
            >> CafeXWeb().reset_actions()

        Returns:
            None
        """
        try:
            self.actions.reset_actions()
        except Exception as e:
            self.logger.exception("Exception in reset_actions method.Exception Details: %s", str(e))
            raise e

    def copy_and_paste(
            self,
            source_locator: Union[str, WebElement],
            destination_locator: Union[str, WebElement],
            explicit_wait: int = None,
    ) -> None:
        """Copy text from the source element and paste it into the destination
        element.

        Examples:
            >> from cafex_ui import CafeXWeb
            >> CafeXWeb().copy_and_paste("xpath=//input[@id='source']", "xpath=//input[@id='destination']")
            >> CafeXWeb().copy_and_paste("xpath=//input[@id='source']", "xpath=//input[@id='destination
        Args:
            source_locator: A string or WebElement representing the source element locator.
            destination_locator: A string or WebElement representing the destination element locator.
            explicit_wait: An optional integer representing the explicit wait time (in seconds) for the elements.

        Returns:
            None

        Raises:
            Exception: If an error occurs during the copy and paste operation.
        """
        try:
            source = self.wca.get_web_element(source_locator, explicit_wait)
            target = self.wca.get_web_element(destination_locator, explicit_wait)
            self.actions.click(source).key_down(Keys.CONTROL).send_keys("a").key_up(
                Keys.CONTROL
            ).perform()
            self.actions.key_down(Keys.CONTROL).send_keys("c").key_up(Keys.CONTROL).perform()
            self.actions.click(target).key_down(Keys.CONTROL).send_keys("v").key_up(
                Keys.CONTROL
            ).perform()
        except Exception as e:
            self.logger.exception(
                "Exception in enter_control_c method.Exception Details: %s", str(e)
            )
            raise e

    def move_by_offset(self, x_offset: int, y_offset: int, then_click: bool = False) -> None:
        """Move the mouse cursor to the x and y offset.

        Examples:
            >> from cafex_ui import CafeXWeb
            >> CafeXWeb().move_by_offset(100, 200)

        Args:
            x_offset: X offset to move to.
            y_offset: Y offset to move to.
            then_click: A boolean representing whether to click after moving to the offset.

        Returns:
            None
        """
        try:
            if then_click:
                self.actions.move_by_offset(x_offset, y_offset).click()
            else:
                self.actions.move_by_offset(x_offset, y_offset).perform()
        except Exception as e:
            self.logger.exception(
                "Exception in move_by_offset method.Exception Details: %s", str(e)
            )
            raise e

    def send_keys(
            self,
            key: str | WebElement,
            locator: Union[str, WebElement] = None,
            explicit_wait: int = None,
    ) -> None:
        """Perform any key operation, including control, escape, backspace,
        delete, etc on any web element or the page.

        Examples:
            >> from cafex_ui import CafeXWeb
            >> CafeXWeb().perform_key_action(key.Keys.CONTROL, "xpath=//input[@id='element']")
            >> CafeXWeb().perform_key_action(key.Keys.ESCAPE)
            >> CafeXWeb().perform_key_action("username")
            >> CafeXWeb().perform_key_action(key.Keys.BACKSPACE, "xpath=//input[@id='element']", 30)

        Args:
            key: A key which needs to be performed.
            locator: A string representing the locator in a fixed format which is, locator_type=locator or WebElement.
            explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

        Returns:
            None
        """
        try:
            explicit_wait = explicit_wait or self.default_explicit_wait
            if locator is not None:
                web_element = self.wca.get_web_element(locator=locator, explicit_wait=explicit_wait)
                self.actions.send_keys_to_element(web_element, key).perform()
            else:
                self.actions.send_keys(key).perform()
        except Exception as e:
            self.logger.exception("Exception in send_keys method. Exception Details: %s", str(e))
            raise e

    def scroll(
            self, x_offset: int = None, y_offset: int = None, locator: Union[str, WebElement] = None
    ) -> None:
        """Scroll to the specified element or scroll by the specified amount.

        Examples:
            >> from cafex_ui import CafeXWeb
            >> CafeXWeb().scroll("xpath=//div[@id='element']", 100, 200)
            >> CafeXWeb().scroll(100, 200)

        Args:
            locator: A string representing the locator in a fixed format which is, locator_type=locator or WebElement.
            x_offset: X offset to move to.
            y_offset: Y offset to move to.

        Returns:
            None
        """
        try:
            if locator is None:
                if x_offset is None or y_offset is None:
                    raise ValueError("x_offset and y_offset must be provided")
                self.actions.scroll_by_amount(x_offset, y_offset).perform()
            else:
                self.actions.scroll_to_element(self.wca.get_web_element(locator)).perform()
        except Exception as e:
            self.logger.exception("Exception in scroll method.Exception Details: %s", str(e))
            raise e

__init__(web_driver=None, default_explicit_wait=None)

Initializes KeyboardMouseActions with a driver and optional explicit wait.

Parameters:

Name Type Description Default
web_driver Remote

The selenium webdriver instance. if not provided, it will be picked from Session Store

None
default_explicit_wait int

The default explicit wait time (in seconds). If not provided, it will be retrieved from ConfigUtils.

None
Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def __init__(self, web_driver: webdriver.Remote = None, default_explicit_wait: int = None):
    """Initializes KeyboardMouseActions with a driver and optional explicit
    wait.

    Args:
        web_driver: The selenium webdriver instance.
                        if not provided, it will be picked from Session Store
        default_explicit_wait: The default explicit wait time (in seconds).
                               If not provided, it will be retrieved from ConfigUtils.
    """
    self.default_explicit_wait = default_explicit_wait or ConfigUtils().get_explicit_wait()
    self.logger = CoreLogger(name=__name__).get_logger()
    self.driver = web_driver or SessionStore().storage.get("driver")
    self.actions = ActionChains(self.driver)
    self.wca = WebClientActions(
        self.driver, default_explicit_wait=self.default_explicit_wait, default_implicit_wait=5
    )

click_and_hold(locator, explicit_wait=None)

Perform click and hold operation on the locator / web element which user passes.

Examples:

from cafex_ui import CafeXWeb CafeXWeb().click_and_hold("xpath=//div[@id='element']") CafeXWeb().click_and_hold("xpath=//div[@id='element']", 30)

Parameters:

Name Type Description Default
locator [str, WebElement]

A string representing the locator in a fixed format which is, locator_type=locator. For example: id=username or xpath=.//*[@id='username'] or web_element

required
explicit_wait int

An integer representing the explicit wait time (in seconds) for the particular element.

None

Returns:

Type Description
None

None

Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
def click_and_hold(self, locator: [str, WebElement], explicit_wait: int = None) -> None:
    """Perform click and hold operation on the locator / web element which
    user passes.

    Examples:
        >> from cafex_ui import CafeXWeb
        >> CafeXWeb().click_and_hold("xpath=//div[@id='element']")
        >> CafeXWeb().click_and_hold("xpath=//div[@id='element']", 30)

    Args:
        locator: A string representing the locator in a fixed format which is, locator_type=locator.
                 For example: id=username or xpath=.//*[@id='username'] or web_element
        explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

    Returns:
        None
    """
    try:
        explicit_wait = explicit_wait or self.default_explicit_wait
        self.actions.click_and_hold(
            self.wca.get_clickable_web_element(locator, explicit_wait)
        ).perform()
    except Exception as e:
        self.logger.exception(
            "Exception in click_and_hold method.Exception Details: %s", str(e)
        )
        raise e

control_click(locator, explicit_wait=None)

Perform control click operation on given web element and the element would be opened in new window.

Examples:

from cafex_ui import CafeXWeb CafeXWeb().control_click("xpath=//a[@id='link']") CafeXWeb().control_click("xpath=//a[@id='link']", 30)

Parameters:

Name Type Description Default
locator Union[str, WebElement]

A string representing the locator in a fixed format which is, locator_type=locator. For example: id=username or xpath=.//*[@id='username'] or web_element

required
explicit_wait int

An integer representing the explicit wait time (in seconds) for the particular element.

None

Returns:

Type Description
None

None

Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
def control_click(self, locator: Union[str, WebElement], explicit_wait: int = None) -> None:
    """Perform control click operation on given web element and the element
    would be opened in new window.

    Examples:
        >> from cafex_ui import CafeXWeb
        >> CafeXWeb().control_click("xpath=//a[@id='link']")
        >> CafeXWeb().control_click("xpath=//a[@id='link']", 30)

    Args:
        locator: A string representing the locator in a fixed format which is, locator_type=locator.
                 For example: id=username or xpath=.//*[@id='username'] or web_element
        explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

    Returns:
        None
    """
    try:
        explicit_wait = explicit_wait or self.default_explicit_wait
        self.actions.key_down(keys.Keys.CONTROL).click(
            self.wca.get_web_element(locator, explicit_wait=explicit_wait)
        ).key_up(keys.Keys.CONTROL).perform()
    except Exception as e:
        self.logger.exception("Exception in control_click method.Exception Details: %s", str(e))
        raise e

copy_and_paste(source_locator, destination_locator, explicit_wait=None)

Copy text from the source element and paste it into the destination element.

Examples:

from cafex_ui import CafeXWeb CafeXWeb().copy_and_paste("xpath=//input[@id='source']", "xpath=//input[@id='destination']") CafeXWeb().copy_and_paste("xpath=//input[@id='source']", "xpath=//input[@id='destination

Args: source_locator: A string or WebElement representing the source element locator. destination_locator: A string or WebElement representing the destination element locator. explicit_wait: An optional integer representing the explicit wait time (in seconds) for the elements.

Returns:

Type Description
None

None

Raises:

Type Description
Exception

If an error occurs during the copy and paste operation.

Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
def copy_and_paste(
        self,
        source_locator: Union[str, WebElement],
        destination_locator: Union[str, WebElement],
        explicit_wait: int = None,
) -> None:
    """Copy text from the source element and paste it into the destination
    element.

    Examples:
        >> from cafex_ui import CafeXWeb
        >> CafeXWeb().copy_and_paste("xpath=//input[@id='source']", "xpath=//input[@id='destination']")
        >> CafeXWeb().copy_and_paste("xpath=//input[@id='source']", "xpath=//input[@id='destination
    Args:
        source_locator: A string or WebElement representing the source element locator.
        destination_locator: A string or WebElement representing the destination element locator.
        explicit_wait: An optional integer representing the explicit wait time (in seconds) for the elements.

    Returns:
        None

    Raises:
        Exception: If an error occurs during the copy and paste operation.
    """
    try:
        source = self.wca.get_web_element(source_locator, explicit_wait)
        target = self.wca.get_web_element(destination_locator, explicit_wait)
        self.actions.click(source).key_down(Keys.CONTROL).send_keys("a").key_up(
            Keys.CONTROL
        ).perform()
        self.actions.key_down(Keys.CONTROL).send_keys("c").key_up(Keys.CONTROL).perform()
        self.actions.click(target).key_down(Keys.CONTROL).send_keys("v").key_up(
            Keys.CONTROL
        ).perform()
    except Exception as e:
        self.logger.exception(
            "Exception in enter_control_c method.Exception Details: %s", str(e)
        )
        raise e

double_click(locator=None, explicit_wait=None)

Perform double click operation on the locator / web element which user passes. If element/locator is not being passed, double click operation gets performed on where cursor point is.

Examples:

from cafex_ui import CafeXWeb CafeXWeb().double_click() CafeXWeb().double_click("xpath=//button[@id='double-click']") CafeXWeb().double_click("xpath=//button[@id='double-click']", 30)

Parameters:

Name Type Description Default
locator Union[str, WebElement]

A string representing the locator in a fixed format which is, locator_type=locator. For example: id=username or xpath=.//*[@id='username'] or web_element

None
explicit_wait int

An integer representing the explicit wait time (in seconds) for the particular element.

None

Returns:

Type Description
None

None

Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
def double_click(
        self, locator: Union[str, WebElement] = None, explicit_wait: int = None
) -> None:
    """Perform double click operation on the locator / web element which
    user passes. If element/locator is not being passed, double click
    operation gets performed on where cursor point is.

    Examples:
        >> from cafex_ui import CafeXWeb
        >> CafeXWeb().double_click()
        >> CafeXWeb().double_click("xpath=//button[@id='double-click']")
        >> CafeXWeb().double_click("xpath=//button[@id='double-click']", 30)

    Args:
        locator: A string representing the locator in a fixed format which is, locator_type=locator.
                 For example: id=username or xpath=.//*[@id='username'] or web_element
        explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

    Returns:
        None
    """
    try:
        explicit_wait = explicit_wait or self.default_explicit_wait
        if locator is not None:
            self.actions.double_click(
                self.wca.get_clickable_web_element(locator, explicit_wait)
            ).perform()
        else:
            self.actions.double_click().perform()
    except Exception as e:
        self.logger.exception("Exception in double_click method.Exception Details: %s", str(e))
        raise e

drag_and_drop(source_element, target_element, explicit_wait=None)

Drag source element and drop source element to the target element.

Examples:

from cafex_ui import CafeXWeb CafeXWeb().drag_and_drop("xpath=//div[@id='source']", "xpath=//div[@id='target']") CafeXWeb().drag_and_drop("xpath=//div[@id='source']", "xpath=//div[@id='target']", 30)

Parameters:

Name Type Description Default
source_element Union[str, WebElement]

A string representing the locator in a fixed format which is, locator_type=locator. For example: id=username or xpath=.//*[@id='username'],or web_element

required
target_element Union[str, WebElement]

A string representing the locator in a fixed format which is, locator_type=locator. For example: id=username or xpath=.//*[@id='username'],or web_element

required
explicit_wait int

An integer representing the explicit wait time (in seconds) for the particular element.

None

Returns:

Type Description
None

None

Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
def drag_and_drop(
        self,
        source_element: Union[str, WebElement],
        target_element: Union[str, WebElement],
        explicit_wait: int = None,
) -> None:
    """Drag source element and drop source element to the target element.

    Examples:
        >> from cafex_ui import CafeXWeb
        >> CafeXWeb().drag_and_drop("xpath=//div[@id='source']", "xpath=//div[@id='target']")
        >> CafeXWeb().drag_and_drop("xpath=//div[@id='source']", "xpath=//div[@id='target']", 30)

    Args:
        source_element: A string representing the locator in a fixed format which is, locator_type=locator.
                        For example: id=username or xpath=.//*[@id='username'],or web_element
        target_element: A string representing the locator in a fixed format which is, locator_type=locator.
                        For example: id=username or xpath=.//*[@id='username'],or web_element
        explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

    Returns:
        None
    """
    try:
        explicit_wait = explicit_wait or self.default_explicit_wait
        self.actions.drag_and_drop(
            self.wca.get_web_element(source_element, explicit_wait=explicit_wait),
            self.wca.get_web_element(target_element, explicit_wait=explicit_wait),
        ).perform()
    except Exception as e:
        self.logger.exception("Exception in drag_and_drop method.Exception Details: %s", str(e))
        raise e

drag_and_drop_by_offset(source_element, x_offset, y_offset, explicit_wait=None)

Hold down the left mouse button on the source element, then move to the target offset and release the mouse button.

Examples:

from cafex_ui import CafeXWeb CafeXWeb().drag_and_drop_by_offset("xpath=//div[@id='source']", 100, 200) CafeXWeb().drag_and_drop_by_offset("xpath=//div[@id='source']", 100, 200, 30)

Parameters:

Name Type Description Default
source_element Union[str, WebElement]

A string representing the locator in a fixed format which is, locator_type=locator. For example: id=username or xpath=.//*[@id='username'] or web_element

required
x_offset int

X offset to move to.

required
y_offset int

Y offset to move to.

required
explicit_wait int

An integer representing the explicit wait time (in seconds) for the particular element.

None

Returns:

Type Description
None

None

Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
def drag_and_drop_by_offset(
        self,
        source_element: Union[str, WebElement],
        x_offset: int,
        y_offset: int,
        explicit_wait: int = None,
) -> None:
    """Hold down the left mouse button on the source element, then move to
    the target offset and release the mouse button.

    Examples:
        >> from cafex_ui import CafeXWeb
        >> CafeXWeb().drag_and_drop_by_offset("xpath=//div[@id='source']", 100, 200)
        >> CafeXWeb().drag_and_drop_by_offset("xpath=//div[@id='source']", 100, 200, 30)

    Args:
        source_element: A string representing the locator in a fixed format which is, locator_type=locator.
                For example: id=username or xpath=.//*[@id='username'] or web_element
        x_offset: X offset to move to.
        y_offset: Y offset to move to.
        explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

    Returns:
        None
    """
    try:
        explicit_wait = explicit_wait or self.default_explicit_wait
        self.actions.drag_and_drop_by_offset(
            self.wca.get_web_element(source_element, explicit_wait), x_offset, y_offset
        ).perform()
    except Exception as e:
        self.logger.exception(
            "Exception in drag_and_drop_by_offset method.Exception Details: %s", str(e)
        )
        raise e

move_by_offset(x_offset, y_offset, then_click=False)

Move the mouse cursor to the x and y offset.

Examples:

from cafex_ui import CafeXWeb CafeXWeb().move_by_offset(100, 200)

Parameters:

Name Type Description Default
x_offset int

X offset to move to.

required
y_offset int

Y offset to move to.

required
then_click bool

A boolean representing whether to click after moving to the offset.

False

Returns:

Type Description
None

None

Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
def move_by_offset(self, x_offset: int, y_offset: int, then_click: bool = False) -> None:
    """Move the mouse cursor to the x and y offset.

    Examples:
        >> from cafex_ui import CafeXWeb
        >> CafeXWeb().move_by_offset(100, 200)

    Args:
        x_offset: X offset to move to.
        y_offset: Y offset to move to.
        then_click: A boolean representing whether to click after moving to the offset.

    Returns:
        None
    """
    try:
        if then_click:
            self.actions.move_by_offset(x_offset, y_offset).click()
        else:
            self.actions.move_by_offset(x_offset, y_offset).perform()
    except Exception as e:
        self.logger.exception(
            "Exception in move_by_offset method.Exception Details: %s", str(e)
        )
        raise e

move_to_element(locator, then_click=False, explicit_wait=None)

Move the mouse cursor to the web element or the locator the cursor needs to move to.

Examples:

from cafex_ui import CafeXWeb CafeXWeb().move_to_element("xpath=//div[@id='element']") CafeXWeb().move_to_element("xpath=//div[@id='element']", 30)

Parameters:

Name Type Description Default
locator Union[str, WebElement]

A string representing the locator in a fixed format which is, locator_type=locator. For example: id=username or xpath=.//*[@id='username'] or web_element

required
then_click bool

A boolean representing whether to click after moving to the element.

False
explicit_wait int

An integer representing the explicit wait time (in seconds) for the particular element.

None

Returns:

Type Description
None

None

Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
def move_to_element(
        self, locator: Union[str, WebElement], then_click: bool = False, explicit_wait: int = None
) -> None:
    """Move the mouse cursor to the web element or the locator the cursor
    needs to move to.

    Examples:
        >> from cafex_ui import CafeXWeb
        >> CafeXWeb().move_to_element("xpath=//div[@id='element']")
        >> CafeXWeb().move_to_element("xpath=//div[@id='element']", 30)

    Args:
        locator: A string representing the locator in a fixed format which is, locator_type=locator.
                 For example: id=username or xpath=.//*[@id='username'] or web_element
        then_click: A boolean representing whether to click after moving to the element.
        explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

    Returns:
        None
    """
    try:
        explicit_wait = explicit_wait or self.default_explicit_wait
        if then_click:
            self.actions.move_to_element(
                self.wca.get_clickable_web_element(locator, explicit_wait)
            ).click()
        else:
            self.actions.move_to_element(
                self.wca.get_clickable_web_element(locator, explicit_wait)
            ).perform()
    except Exception as e:
        self.logger.exception(
            "Exception in move_to_element method.Exception Details: %s", str(e)
        )
        raise e

move_to_element_with_offset(locator, x_offset, y_offset, explicit_wait=None)

Move the mouse cursor to the web element or the locator the cursor needs to move to.

Examples:

from cafex_ui import CafeXWeb CafeXWeb().move_to_element_by_offset("xpath=//div[@id='element']", 100, 200) CafeXWeb().move_to_element_by_offset("xpath=//div[@id='element']", 100, 200, 30)

Parameters:

Name Type Description Default
locator Union[str, WebElement]

A string representing the locator in a fixed format which is, locator_type=locator. For example: id=username or xpath=.//*[@id='username'] or web_element

required
x_offset int

X offset to move to.

required
y_offset int

Y offset to move to.

required
explicit_wait int

An integer representing the explicit wait time (in seconds) for the particular element.

None

Returns:

Type Description
None

None

Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
def move_to_element_with_offset(
        self,
        locator: Union[str, WebElement],
        x_offset: int,
        y_offset: int,
        explicit_wait: int = None,
) -> None:
    """Move the mouse cursor to the web element or the locator the cursor
    needs to move to.

    Examples:
        >> from cafex_ui import CafeXWeb
        >> CafeXWeb().move_to_element_by_offset("xpath=//div[@id='element']", 100, 200)
        >> CafeXWeb().move_to_element_by_offset("xpath=//div[@id='element']", 100, 200, 30)

    Args:
        locator: A string representing the locator in a fixed format which is, locator_type=locator.
                 For example: id=username or xpath=.//*[@id='username'] or web_element
        x_offset: X offset to move to.
        y_offset: Y offset to move to.
        explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

    Returns:
        None
    """
    try:
        explicit_wait = explicit_wait or self.default_explicit_wait
        self.actions.move_to_element_with_offset(
            self.wca.get_clickable_web_element(locator, explicit_wait), x_offset, y_offset
        ).perform()
    except Exception as e:
        self.logger.exception(
            "Exception in move_to_element_by_offset method.Exception Details: %s", str(e)
        )
        raise e

release(key=None)

Release all the keys which are pressed.If single key specified, it releases that key.

Examples:

from cafex_ui import CafeXWeb CafeXWeb().release() CafeXWeb().release(keys.Keys.CONTROL)

Parameters:

Name Type Description Default
key str

A key which needs to be released.

None

Returns:

Type Description
None

None

Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
def release(self, key: str = None) -> None:
    """Release all the keys which are pressed.If single key specified, it
    releases that key.

    Examples:
        >> from cafex_ui import CafeXWeb
        >> CafeXWeb().release()
        >> CafeXWeb().release(keys.Keys.CONTROL)

    Args:
        key: A key which needs to be released.

    Returns:
        None
    """
    try:
        if key is not None:
            self.actions.key_up(key).perform()
        else:
            self.actions.release().perform()
    except Exception as e:
        self.logger.exception("Exception in release method.Exception Details: %s", str(e))
        raise e

reset_actions()

Reset the actions.

Examples:

from cafex_ui import CafeXWeb CafeXWeb().reset_actions()

Returns:

Type Description
None

None

Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
def reset_actions(self) -> None:
    """Reset the actions.

    Examples:
        >> from cafex_ui import CafeXWeb
        >> CafeXWeb().reset_actions()

    Returns:
        None
    """
    try:
        self.actions.reset_actions()
    except Exception as e:
        self.logger.exception("Exception in reset_actions method.Exception Details: %s", str(e))
        raise e

right_click(locator=None, explicit_wait=None)

Perform right click operation on the locator / web element which user passes. If element/locator is not being passed, right click operation gets performed on where cursor point is.

Examples:

from cafex_ui import CafeXWeb CafeXWeb().right_click() CafeXWeb().right_click("xpath=//div[@id='context-menu']") CafeXWeb().right_click("xpath=//div[@id='context-menu']", 30)

Parameters:

Name Type Description Default
locator Union[str, WebElement]

A string representing the locator in a fixed format which is, locator_type=locator. For example: id=username or xpath=.//*[@id='username'] or web_element

None
explicit_wait int

An integer representing the explicit wait time (in seconds) for the particular element.

None

Returns:

Type Description
None

None

Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
def right_click(
        self, locator: Union[str, WebElement] = None, explicit_wait: int = None
) -> None:
    """Perform right click operation on the locator / web element which
    user passes. If element/locator is not being passed, right click
    operation gets performed on where cursor point is.

    Examples:
        >> from cafex_ui import CafeXWeb
        >> CafeXWeb().right_click()
        >> CafeXWeb().right_click("xpath=//div[@id='context-menu']")
        >> CafeXWeb().right_click("xpath=//div[@id='context-menu']", 30)

    Args:
        locator: A string representing the locator in a fixed format which is, locator_type=locator.
                 For example: id=username or xpath=.//*[@id='username'] or web_element
        explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

    Returns:
        None
    """
    try:
        explicit_wait = explicit_wait or self.default_explicit_wait
        if locator is not None:
            self.actions.context_click(
                self.wca.get_clickable_web_element(locator, explicit_wait)
            ).perform()
        else:
            self.actions.context_click().perform()
    except Exception as e:
        self.logger.exception("Exception in right_click method.Exception Details: %s", str(e))
        raise e

robust_click(locator, explicit_wait=None)

Click on the locator provided.It will find the element for the locator given, convert it into a web element then wait for it to be clickable. The time of wait will depend on the value passed in the explicit wait.

Examples:

from cafex_ui import CafeXWeb CafeXWeb().robust_click("xpath=//a[@class='advanced-search-link']") CafeXWeb().robust_click("xpath=//a[@class='advanced-search-link']", 30)

Parameters:

Name Type Description Default
locator Union[str, WebElement]

A string representing the locator in a fixed format which is, locator_type=locator/web_element. For example: id=username or xpath=.//*[@id='username'] or web_element

required
explicit_wait int

An integer representing the explicit wait time (in seconds) for the particular element.

None

Returns:

Type Description
None

None

Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def robust_click(self, locator: Union[str, WebElement], explicit_wait: int = None) -> None:
    """Click on the locator provided.It will find the element for the
    locator given, convert it into a web element then wait for it to be
    clickable. The time of wait will depend on the value passed in the
    explicit wait.

    Examples:
        >> from cafex_ui import CafeXWeb
        >> CafeXWeb().robust_click("xpath=//a[@class='advanced-search-link']")
        >> CafeXWeb().robust_click("xpath=//a[@class='advanced-search-link']", 30)

    Args:
        locator: A string representing the locator in a fixed format which is, locator_type=locator/web_element.
                 For example: id=username or xpath=.//*[@id='username'] or web_element
        explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

    Returns:
        None
    """
    try:
        explicit_wait = explicit_wait or self.default_explicit_wait
        self.wca.get_clickable_web_element(locator, explicit_wait).click()
    except Exception:
        try:
            self.actions.click(
                self.wca.get_clickable_web_element(locator, explicit_wait)
            ).perform()
        except Exception:
            try:
                self.wca.execute_javascript(
                    "arguments[0].click();",
                    self.wca.get_clickable_web_element(locator, explicit_wait),
                )
            except Exception as e3:
                self.logger.exception(
                    "Exception in robust_click method. Exception Details:", exc_info=e3
                )
                raise e3

scroll(x_offset=None, y_offset=None, locator=None)

Scroll to the specified element or scroll by the specified amount.

Examples:

from cafex_ui import CafeXWeb CafeXWeb().scroll("xpath=//div[@id='element']", 100, 200) CafeXWeb().scroll(100, 200)

Parameters:

Name Type Description Default
locator Union[str, WebElement]

A string representing the locator in a fixed format which is, locator_type=locator or WebElement.

None
x_offset int

X offset to move to.

None
y_offset int

Y offset to move to.

None

Returns:

Type Description
None

None

Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
def scroll(
        self, x_offset: int = None, y_offset: int = None, locator: Union[str, WebElement] = None
) -> None:
    """Scroll to the specified element or scroll by the specified amount.

    Examples:
        >> from cafex_ui import CafeXWeb
        >> CafeXWeb().scroll("xpath=//div[@id='element']", 100, 200)
        >> CafeXWeb().scroll(100, 200)

    Args:
        locator: A string representing the locator in a fixed format which is, locator_type=locator or WebElement.
        x_offset: X offset to move to.
        y_offset: Y offset to move to.

    Returns:
        None
    """
    try:
        if locator is None:
            if x_offset is None or y_offset is None:
                raise ValueError("x_offset and y_offset must be provided")
            self.actions.scroll_by_amount(x_offset, y_offset).perform()
        else:
            self.actions.scroll_to_element(self.wca.get_web_element(locator)).perform()
    except Exception as e:
        self.logger.exception("Exception in scroll method.Exception Details: %s", str(e))
        raise e

send_keys(key, locator=None, explicit_wait=None)

Perform any key operation, including control, escape, backspace, delete, etc on any web element or the page.

Examples:

from cafex_ui import CafeXWeb CafeXWeb().perform_key_action(key.Keys.CONTROL, "xpath=//input[@id='element']") CafeXWeb().perform_key_action(key.Keys.ESCAPE) CafeXWeb().perform_key_action("username") CafeXWeb().perform_key_action(key.Keys.BACKSPACE, "xpath=//input[@id='element']", 30)

Parameters:

Name Type Description Default
key str | WebElement

A key which needs to be performed.

required
locator Union[str, WebElement]

A string representing the locator in a fixed format which is, locator_type=locator or WebElement.

None
explicit_wait int

An integer representing the explicit wait time (in seconds) for the particular element.

None

Returns:

Type Description
None

None

Source code in libs\cafex_ui\src\cafex_ui\web_client\keyboard_mouse_actions.py
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
def send_keys(
        self,
        key: str | WebElement,
        locator: Union[str, WebElement] = None,
        explicit_wait: int = None,
) -> None:
    """Perform any key operation, including control, escape, backspace,
    delete, etc on any web element or the page.

    Examples:
        >> from cafex_ui import CafeXWeb
        >> CafeXWeb().perform_key_action(key.Keys.CONTROL, "xpath=//input[@id='element']")
        >> CafeXWeb().perform_key_action(key.Keys.ESCAPE)
        >> CafeXWeb().perform_key_action("username")
        >> CafeXWeb().perform_key_action(key.Keys.BACKSPACE, "xpath=//input[@id='element']", 30)

    Args:
        key: A key which needs to be performed.
        locator: A string representing the locator in a fixed format which is, locator_type=locator or WebElement.
        explicit_wait: An integer representing the explicit wait time (in seconds) for the particular element.

    Returns:
        None
    """
    try:
        explicit_wait = explicit_wait or self.default_explicit_wait
        if locator is not None:
            web_element = self.wca.get_web_element(locator=locator, explicit_wait=explicit_wait)
            self.actions.send_keys_to_element(web_element, key).perform()
        else:
            self.actions.send_keys(key).perform()
    except Exception as e:
        self.logger.exception("Exception in send_keys method. Exception Details: %s", str(e))
        raise e