Python 硒:等待元素';s高度不等于X

Python 硒:等待元素';s高度不等于X,python,selenium,Python,Selenium,当画布高度改变时,我试图截取网页的截图。其默认高度为557。我希望selenium等待高度更改为557以外的任何其他值。有办法吗 <canvas id="faceCanvasPhoto" width="600" height="557" class="center-block reportCanvas"> Your browser does not support the canvas eleme

当画布高度改变时,我试图截取网页的截图。其默认高度为557。我希望selenium等待高度更改为557以外的任何其他值。有办法吗

<canvas id="faceCanvasPhoto" width="600" height="557" class="center-block reportCanvas">
    Your browser does not support the canvas element.
</canvas>

定义您的等待类:

class element_height_changes(object):
    """An expectation for checking that an element has a particular css class.

      locator - used to find the element
      returns the WebElement once it has the particular css class
      """

    def __init__(self, locator, curnt_val):
        self.locator = locator
        self.curnt_val = curnt_val

    def __call__(self, driver):
        # Finding the referenced element
       element = driver.find_element(*self.locator)
       if element.get_attribute("height") == str(self.curnt_val):
          return False
       else:
          return True
并称之为:

print(WebDriverWait(driver, 10).until(
    element_height_changes(
        (By.XPATH, "//iframe"),59)
))

无论iframe长度是否从59更改,这都将打印true或false。如果不等到10秒,它就会改变,否则超时。

我不知道我是否做错了什么。仍然没有运气WebDriverWait(driver,5)。直到(元素高度改变((By.XPATH,“/*[@id='faceCanvasPhoto']),557)什么是错误没有收到任何错误感觉好像它没有等待高度改变如果高度在10秒内没有改变,它会抛出超时elese它会给出正确的答案我认为它需要0.1秒的睡眠,然后才能按照代码截图。
print(WebDriverWait(driver, 10).until(
    element_height_changes(
        (By.XPATH, "//iframe"),59)
))