gpt4 book ai didi

python - Selenium:WAITING元素的高度不等于 X

转载 作者:行者123 更新时间:2023-12-04 13:29:57 25 4
gpt4 key购买 nike

当 Canvas 高度改变时,我试图截取网页的屏幕截图。它的默认高度为 557。我希望 selenium 等到高度更改为 557 以外的任何其他值。有什么办法可以做到这一点?

<canvas id="faceCanvasPhoto" width="600" height="557" class="center-block reportCanvas">
Your browser does not support the canvas element.
</canvas>
我尝试了 EC.visibility_of_element_located 但无法捕获它
try:                                                  
WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.XPATH, "//*[@id='faceCanvasPhoto']"))
)
driver.find_element_by_tag_name('body').screenshot(facemap +'.png')
except TimeoutException:
driver.find_element_by_tag_name('body').screenshot(facemap +'.png')
driver.implicitly_wait(1)

最佳答案

定义你的等待类:

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)
))
这将打印 true 或 false ,无论 iframe 长度是否从 59 更改。如果不等到 10 秒更改其他超时。

关于python - Selenium:WAITING元素的高度不等于 X,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65678988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com