element_interactions
ElementInteractions
This class contains methods to perform various operations on a browser and its elements.
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
14 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 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
|
__init__(web_driver=None, default_explicit_wait=None, default_implicit_wait=None)
Initializes WebClientActions with a driver and optional explicit wait.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
web_driver
|
WebDriver
|
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\web_client_actions\element_interactions.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
click(locator, explicit_wait=None)
Click on the locator provided.
Examples:
from cafex_ui import CafeXWeb CafeXWeb().click("xpath=//a[@class='advanced-search-link']") CafeXWeb().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. 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\web_client_actions\element_interactions.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
deselect_dropdown_value(locator, explicit_wait=None, visible_text=None, value=None, index=None, deselect_all=False)
Deselect a value from a multiselect dropdown. This method works for elements with the "select" tag and supports multiselect options.
Examples:
from cafex_ui import CafeXWeb CafeXWeb().deselect_dropdown_value("xpath=//*[@name='dropdown']", value="option1")
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'] |
required |
explicit_wait
|
int
|
An integer representing the explicit wait time (in seconds) for the particular element. |
None
|
visible_text
|
str
|
A string representing the text to be deselected from the dropdown. |
None
|
value
|
str
|
A string representing the value to be deselected from the dropdown. |
None
|
index
|
int
|
An integer representing the index of the value to be deselected from the dropdown. |
None
|
deselect_all
|
bool
|
A boolean to deselect all the values from the dropdown. |
False
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
|
execute_javascript(script, *args)
Execute the JavaScript code passed in the 'script' parameter with additional parameters for the script (if required).
Examples:
from cafex_ui import CafeXWeb CafeXWeb().execute_javascript("document.getElementById('some_id').value='someValue';") CafeXWeb().execute_javascript("arguments[0].click();", web_element)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
script
|
str
|
A string representing the actual JavaScript code that needs to be executed. |
required |
*args
|
Additional arguments for the script (if required). |
()
|
Returns:
Type | Description |
---|---|
str
|
A string or None, depending on the JavaScript code. |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
|
find_relative_element(by, value, relative_by, relative_element=None, explicit_wait=None)
Finds an element relative to another element.
Examples:
from cafex_ui import CafeXWeb CafeXWeb().find_relative_element(By.NAME, "btnK", "below", search_box) CafeXWeb().find_relative_element(By.NAME, "btnK", "near", search_box, distance=50)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
by
|
Locator strategy for the target element (e.g., By.NAME, By.XPATH). |
required | |
value
|
str
|
Locator value for the target element. |
required |
relative_by
|
str
|
Relative position method (e.g., below, above, to_left_of, to_right_of, near). |
required |
relative_element
|
Union[str, WebElement]
|
The reference WebElement or locator. |
None
|
explicit_wait
|
int
|
The explicit wait time (in seconds) for the particular element. |
None
|
Returns:
Type | Description |
---|---|
The located WebElement. |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
|
get_attribute_value(locator, attribute, explicit_wait=None)
Return the attribute value for the web element or find the web element using the locator passed and then return the attribute value of the web element.
Examples:
from cafex_ui import CafeXWeb CafeXWeb().get_attribute_value("xpath=//*[@name='password']", "class")
This will find the web_element using the xpath in the first parameter then return the value of the class
attribute for that web element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
locator
|
Union[str, WebElement]
|
A string or WebElement representing the locator in a fixed format which is, locator_type=locator. For example: id=username or xpath=.//*[@id='username'] |
required |
attribute
|
str
|
A string representing the attribute for which the value will be returned. |
required |
explicit_wait
|
int
|
An integer representing the explicit wait time (in seconds) for the particular element. |
None
|
Returns:
Type | Description |
---|---|
str
|
A string representing the attribute value. |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
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 |
|
get_child_elements(parent_locator=None, search_locator=None)
Return the first available child of the element provided.
Examples:
from cafex_ui import CafeXWeb p_element = CafeXWeb().get_web_element("xpath=//div[@id='parent']") child_element = CafeXWeb().get_child_elements(parent_locator=parent_element, search_locator="xpath=./*[@name='child']")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent_locator
|
Union[str, WebElement]
|
A WebElement or string representing the element on which child elements need to be searched. Locator can only be xpath/id/css/classname/tag_name/name/link_text or web element. |
None
|
search_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
|
Returns:
Type | Description |
---|---|
List[WebElement] | None
|
A WebElement representing the first available child element. |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
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 |
|
get_clickable_web_element(locator, explicit_wait=None)
Verify if the given locator is present and clickable and return the web element for the locator.
Examples:
from cafex_ui import CafeXWeb CafeXWeb().get_clickable_web_element("xpath=//*[@name='password']")
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'] |
required |
explicit_wait
|
int
|
An integer representing the explicit wait time (in seconds) for the particular element. |
None
|
Returns:
Type | Description |
---|---|
WebElement
|
A WebElement representing the located element. |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
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 |
|
get_locator_strategy(pstr_locator_strategy)
Get the locator strategy.
Examples:
from cafex_ui import CafeXWeb CafeXWeb().get_locator_strategy("xpath")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pstr_locator_strategy
|
A string representing the locator strategy. |
required |
Returns:
Type | Description |
---|---|
The locator strategy. |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
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 |
|
get_selected_dropdown_values(locator, explicit_wait=None, first_selected_option=False, all_selected_options=False, options=False)
Get the selected value(s) from a dropdown. This method works for elements with the "select" tag.
Examples:
from cafex_ui import CafeXWeb CafeXWeb().get_selected_dropdown_values("xpath=//*[@name='dropdown']", first_selected_option=True)
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'] |
required |
explicit_wait
|
int
|
An integer representing the explicit wait time (in seconds) for the particular element. |
None
|
first_selected_option
|
bool
|
A boolean to get the first selected option from the dropdown. |
False
|
all_selected_options
|
bool
|
A boolean to get all selected options from the dropdown. |
False
|
options
|
bool
|
A boolean to get all options from the dropdown. |
False
|
Returns:
Type | Description |
---|---|
Union[str, List[str]]
|
A string or list of strings representing the selected value(s) from the dropdown. |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 |
|
get_web_element(locator, explicit_wait=None)
Verify if the given locator is present and return the web element for the locator.
Examples:
from cafex_ui import CafeXWeb CafeXWeb().get_web_element("xpath=//*[@name='password']")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
locator
|
Union[str, WebElement]
|
A string or WebElement representing the locator in a fixed format which is, locator_type=locator. For example: id=username or xpath=.//*[@id='username'] |
required |
explicit_wait
|
int
|
An integer representing the explicit wait time (in seconds) for the particular element. |
None
|
Returns:
Type | Description |
---|---|
WebElement
|
A WebElement representing the located element. |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
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 |
|
get_web_elements(locator, explicit_wait=None)
Verify if the given locator is present and return list of all web elements matching this locator.
Examples:
from cafex_ui import CafeXWeb CafeXWeb().get_web_elements("xpath=//*[@name='password']")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
locator
|
str
|
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 |
---|---|
List[WebElement]
|
A list of WebElements representing the located elements. |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
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 |
|
get_xpath(**kwargs)
Create an xpath for the given tag/element type, attribute, and its value.
Examples:
from cafex_ui import CafeXWeb CafeXWeb().get_xpath(tag='a', attribute='text', value='new')
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tag
|
A string representing the element type. For example: a or input or div. |
required | |
attribute
|
A string representing the name of the attribute. For example: value. |
required | |
value
|
A string representing the value of the attribute. |
required |
Returns:
Type | Description |
---|---|
str
|
A string representing the constructed xpath. |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|
highlight_web_element(locator, highlight_time=0.5)
Highlight the web element.
Examples:
from cafex_ui import CafeXWeb CafeXWeb().highlight_web_element("xpath=//[@name='password']") CafeXWeb().highlight_web_element("xpath=//[@name='password']", 0.25)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
locator
|
Union[str, WebElement]
|
A string or WebElement representing the locator in a fixed format which is, locator_type=locator. For example: id=username or xpath=.//*[@id='username'] |
required |
highlight_time
|
float
|
A float representing the time (in seconds) for which the element needs to be highlighted. |
0.5
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
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 |
|
is_element_displayed(locator, explicit_wait=None)
Verify if the given locator is present and visible on the page.
Examples:
from cafex_ui import CafeXWeb CafeXWeb().is_element_displayed("xpath=//*[@name='password']")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
locator
|
Union[str, WebElement]
|
A string or WebElement representing the locator in a fixed format which is, locator_type=locator. For example: id=username or xpath=.//*[@id='username'] |
required |
explicit_wait
|
int
|
An integer representing the explicit wait time (in seconds) for the particular element. |
None
|
Returns:
Type | Description |
---|---|
bool
|
A boolean indicating if the element is displayed. |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
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 |
|
is_element_present(locator, explicit_wait=None)
Verify if the given locator or web element is present on the page.
Examples:
from cafex_ui import CafeXWeb CafeXWeb().is_element_present("xpath=//*[@name='password']")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
locator
|
Union[str, WebElement]
|
A string or WebElement 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 |
---|---|
bool
|
A boolean indicating if the element is present. |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
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 |
|
select_dropdown_value(locator, explicit_wait=None, visible_text=None, value=None, index=None)
Select a value from a dropdown. This method works for elements with the "select" tag.
Examples:
from cafex_ui import CafeXWeb CafeXWeb().select_dropdown_value("xpath=//[@name='dropdown']", visible_text='text') CafeXWeb().select_dropdown_value("xpath=//[@name='dropdown']", value='text') CafeXWeb().select_dropdown_value("xpath=//*[@name='dropdown']", index=1)
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'] |
required |
explicit_wait
|
int
|
An integer representing the explicit wait time (in seconds) for the particular element. |
None
|
visible_text
|
str
|
A string representing the text to be selected from the dropdown. |
None
|
value
|
str
|
A string representing the value to be selected from the dropdown. |
None
|
index
|
int
|
An integer representing the index of the value to be selected from the dropdown. |
None
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
|
type(locator, text=None, clear=False, explicit_wait=None, click_before_type=True)
Type the given value on the locator provided.If clear is set to True, the respective field content will be cleared and by default click_before_type is set to True, which means the element will be clicked before typing the given text.
Examples:
from cafex_ui import CafeXWeb CafeXWeb().type("xpath=//a[@class='username']", "your_username") CafeXWeb().type("xpath=//a[@class='username']", "your_username", explicit_wait=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 |
text
|
str
|
A string representing the value to be typed into the web element. |
None
|
explicit_wait
|
int
|
An integer representing the explicit wait time (in seconds) for the particular element. |
None
|
clear
|
bool
|
A boolean to use clear feature, if set to True respective field content will be cleared. By default, this is set to False. |
False
|
click_before_type
|
bool
|
A boolean to determine whether there will be a click on the element or not before typing the given text. |
True
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
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 |
|
wait_for_invisibility_web_element(locator, explicit_wait=None)
Wait until the locator passed is invisible and return True or False based on whether the element is invisible or not.
Examples:
from cafex_ui import CafeXWeb CafeXWeb().wait_for_invisibility_web_element("xpath=//*[@name='password']")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
locator
|
str
|
A string representing the locator in a fixed format which is, locator_type=locator. For example: id=username or xpath=.//*[@id='username'] |
required |
explicit_wait
|
int
|
An integer representing the explicit wait time (in seconds) for the particular element. |
None
|
Returns:
Type | Description |
---|---|
WebElement | bool
|
A boolean indicating if the element is invisible. |
Source code in libs\cafex_ui\src\cafex_ui\web_client\web_client_actions\element_interactions.py
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 |
|