0

I am trying to automate the monitoring of a system process using Selenium Grid, standalone chrome 4.5.0 (revision fe167b119a, currently beta). On-screen there's a pinned pop-up with a progress bar, the xpath definition for which I have specified in xpath_elements['progress_bar']. The width component of the style attribute of this element increases with progress of the process.

I have the following code excerpts as I attempt to follow and log the progressive lengthening of this progress bar. class process_progress_test provides the custom wait condition, implemented per Create custom wait until condition in Python.

class process_progress_test:
    def __init__(self, xpath_locator, value):
        #self._driver = driver
        self._xpath_locator = xpath_locator
        #self._attribute = attr
        self._attribute_value = value
        
        self._width_re = re.compile('width: (\d+)px;')

    def __call__(self, driver):
        
        prog_bar = driver.find_element(By.XPATH, self._xpath_locator)
        print(prog_bar.size)
        style = prog_bar.get_attribute('style')

        if width_m := self._width_re.search(style):
            print(width_m)
            width = int(width_m.group(1))
            print(width)
            if width > self._attribute_value:
                print(f"self._attribute_value = {self._attribute_value}")
                return {'width': width, 'fraction': round((width / 500.), 3)}
            else:
                return False
        else:
            self.log.error(f"didn't match style: style = {style}")
            return 1
    

class System_Session(object):
    ...
    
    def _wait_for_system_process(self):
        """Monitor Process Progress

        Track job progress, continue with system interaction when job complete
        """

        print('_waiting_for_process()')
        
        # monitor "job running" window
        running = dict()
        ppx = -1
        while running := self._job_running_pinned_popup(ppx):
            if isinstance(running, dict):
                ppx = running['width']
                print(f"Progress: {running['width']} px, {100 * running['fraction']} % ")
            elif running == 1:
                exit()

    def _job_running_pinned_popup(self, previous_progress_px):
        """Monitor Progress Poppup

        Simple function to check whether pinned popup is still there, and if not wait
        and watch for an update to the progress width. Input the last px width integer
        """

        if not self.driver.find_element(By.XPATH, xpath_elements['job_running']):
            return False
        
        return WebDriverWait(self.driver, 60).until(
            process_progress_test(xpath_elements['progress_bar'], previous_progress_px)
        )

The progress bar starts of at zero, and I pick up this increase from -1, but thereafter it appears that changes to source are not picked up.

I've tried re-calling driver.page_source (and processing instead with BeautifulSoup), and including driver.execute_script("return document.documentElement.outerHTML"), with no success -- it does not pick up any new updates to the page element width style. driver.refresh() actually loses the original page altogether. I've found another variation on the theme that suggests to wrap the expected condition in ExpectedConditions.refreshed(), but the python equivalent (expected_conditions) has no refreshed method (https://www.selenium.dev/selenium/docs/api/py/webdriver_support/selenium.webdriver.support.expected_conditions.html).

Maybe everything I could find is dated now. How do we trigger selenium to capture the same changes I can see in the element via developer tools?

GoneAsync
  • 349
  • 5
  • 18

0 Answers0