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 |
|
__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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|