[英]How to access the window size of a frame with python selenium?
在 python selenium 我通過選擇 iframe
frame = driver.find_element(*locator)
driver.switch_to.frame(frame)
然后稍后我嘗試訪問該 iframe 的大小。 我嘗試了以下方法:
frame.get_window_rect()
frame.get_window_size()
frame.contentWindow.get_window_rect()
frame.contentWindow.get_window_size()
但看起來元素 'frame' 既沒有屬性 'get_window_rect , nor 'get_window_size
,也沒有contentWindow
。 那么如何訪問 iframe 元素/窗口/矩形/其他的大小?
切換到 iframe后,我需要這些信息。
get_window_rect()
和get_window_size()
是 webdriver 方法。 Webelements 具有rect
和size
屬性
frame = driver.find_element(*locator)
rect = frame.rect # {'height': 888, 'width': 912}
請注意,切換到frame
元素后,您將無法使用它,它不再位於驅動程序上下文中,它將拋出StaleElementReferenceException
。
要在切換到<iframe>
后獲取大小,可以使用<html>
標簽
rect = driver.find_element_by_tag_name('html').rect
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.