(driver, selector, loops=4, o_bs="")
| 423 | |
| 424 | |
| 425 | def highlight_with_js(driver, selector, loops=4, o_bs=""): |
| 426 | with suppress(Exception): |
| 427 | # This closes any pop-up alerts |
| 428 | execute_script(driver, "") |
| 429 | if selector == "html": |
| 430 | selector = "body" |
| 431 | selector_no_spaces = selector.replace(" ", "") |
| 432 | early_exit = False |
| 433 | if '[style=\\"' in selector_no_spaces: |
| 434 | if "box\\-shadow:" in selector: |
| 435 | early_exit = True # Changing the box-shadow changes the selector |
| 436 | elif '[style=\\"' in selector: |
| 437 | selector = selector.replace('[style=\\"', '[style\\*=\\"') |
| 438 | else: |
| 439 | early_exit = True # Changing the box-shadow changes the selector |
| 440 | if early_exit: |
| 441 | return |
| 442 | script = ( |
| 443 | """document.querySelector('%s').style.boxShadow = |
| 444 | '0px 0px 6px 6px rgba(128, 128, 128, 0.5)';""" |
| 445 | % selector |
| 446 | ) |
| 447 | try: |
| 448 | execute_script(driver, script) |
| 449 | except Exception: |
| 450 | return |
| 451 | for n in range(loops): |
| 452 | script = ( |
| 453 | """document.querySelector('%s').style.boxShadow = |
| 454 | '0px 0px 6px 6px rgba(255, 0, 0, 1)';""" |
| 455 | % selector |
| 456 | ) |
| 457 | try: |
| 458 | execute_script(driver, script) |
| 459 | except Exception: |
| 460 | return |
| 461 | time.sleep(0.0181) |
| 462 | script = ( |
| 463 | """document.querySelector('%s').style.boxShadow = |
| 464 | '0px 0px 6px 6px rgba(128, 0, 128, 1)';""" |
| 465 | % selector |
| 466 | ) |
| 467 | try: |
| 468 | execute_script(driver, script) |
| 469 | except Exception: |
| 470 | return |
| 471 | time.sleep(0.0181) |
| 472 | script = ( |
| 473 | """document.querySelector('%s').style.boxShadow = |
| 474 | '0px 0px 6px 6px rgba(0, 0, 255, 1)';""" |
| 475 | % selector |
| 476 | ) |
| 477 | try: |
| 478 | execute_script(driver, script) |
| 479 | except Exception: |
| 480 | return |
| 481 | time.sleep(0.0181) |
| 482 | script = ( |
nothing calls this directly
no test coverage detected
searching dependent graphs…