1

I am trying to detect the presence of text (underlying text regardless of the visibility) that is blinking caused by this jquery:

    /* Blink thingy*/
$('.blink').each(function() {
    var elem = $(this);
    setInterval(function() {
        if (elem.css('visibility') == 'hidden') {
            elem.css('visibility', 'visible');
        } else {
            elem.css('visibility', 'hidden');
        }    
    }, 500);
});

So far I get hit an miss results with:

UpdateTaskCompleteElement = driver.find_element_by_xpath("/html/body/div[3]/h3/span")

and

UpdateTaskCompleteMessage = UpdateTaskCompleteElement.text
if UpdateTaskCompleteMessage == ExpectedUTCMessage:
     #Make a log entry
else:
     #Throw an error

What is the best way to capture the message between blinks? Is there a function in python or selenium that can solve this?

I've been tempted to put the python in a loop and let it run ten times but I think this would just reduce the chances and I would still have to re-run the script occasionally {It's a long script :( }.

Mattman85208
  • 1,858
  • 2
  • 29
  • 51

3 Answers3

1

A better approach in this case would be to wait for a specific element to have a specific text:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 10)
wait.until(EC.text_to_be_present_in_element((By.XPATH, "/html/body/div[3]/h3/span"), ExpectedUTCMessage))

This would wait up to 10 seconds checking the presence of the ExpectedUTCMessage text in the element every half a second.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
0

What about find_element_by_css_selector("blink") ? The JQuery does not change the text -- just whether or not it's visible.

Selenium python find_element_by_class_name() stopped working from v 2.2 to 2.21 -- cannot use 'Compound Class Name'

Selenium Finding elements by class name in python

Community
  • 1
  • 1
john mangual
  • 7,718
  • 13
  • 56
  • 95
  • I'm not having any trouble finding the element, just the text is sometimes empty. Since it works about half time I'm assuming it is just the blink that is making it empty (Not visible). – Mattman85208 Jan 18 '16 at 22:28
0

Since the answers are so far off and no body else is posting anything better, here is my Loop test. I don't really like this but it does work.

ExpectedUTCMessage = "Whatever the message should be."
UpdateTaskCompleteElement = driver.find_element_by_xpath("/html/body/div[3]/h3/span")


BlinkDetectLoopPass = False
for BlinkChecknum in range(0,20): # I'm using 20 loops because I have seen as many as 9 failed attempts

    UpdateTaskCompleteMessage = UpdateTaskCompleteElement.text

    if UpdateTaskCompleteMessage == ExpectedUTCMessage:
        BlinkDetectLoopPass = True
        break
    else:
        #Just displaying the failed detections, don't really need this else
        print("\nUpdate Task Complete Message missed blink check #" + str(BlinkChecknum + 1) + ".\n")

if BlinkDetectLoopPass:
    #Success Handling
else:
    #Error Handling

Please post anything better, thanks!!!

Mattman85208
  • 1,858
  • 2
  • 29
  • 51