麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > Python > 正文

Python+selenium 獲取瀏覽器窗口坐標、句柄的方法

2020-02-15 23:10:55
字體:
來源:轉載
供稿:網友

1.0 獲取瀏覽器窗口坐標

python目錄可找到Webdriver.py 文件定義了get_window_rect()函數,可獲取窗口的坐標和大小(長寬),但出現”Command not found”的情況。set_window_rect()函數也一樣。

def get_window_rect(self): """ Gets the x, y coordinates of the window as well as height and width of the current window. :Usage:  driver.get_window_rect() """ return self.execute(Command.GET_WINDOW_RECT)['value']def set_window_rect(self, x=None, y=None, width=None, height=None): """ Sets the x, y coordinates of the window as well as height and width of the current window. :Usage:  driver.set_window_rect(x=10, y=10)  driver.set_window_rect(width=100, height=200)  driver.set_window_rect(x=10, y=10, width=100, height=200) """ if (x is None and y is None) and (height is None and width is None):  raise InvalidArgumentException("x and y or height and width need values") return self.execute(Command.SET_WINDOW_RECT,   {"x": x, "y": y, "width": width, "height": height})['value']

然而Webdriver.py文件還定義了get_window_position()函數和get_window_size()函數,可以用這兩個函數來分別獲取窗口的坐標和大小,而不需要用到win32gui的方法。

def get_window_size(self, windowHandle='current'):  """  Gets the width and height of the current window.  :Usage:   driver.get_window_size()  """  command = Command.GET_WINDOW_SIZE  if self.w3c:   if windowHandle != 'current':    warnings.warn("Only 'current' window is supported for W3C compatibile browsers.")   size = self.get_window_rect()  else:   size = self.execute(command, {'windowHandle': windowHandle})  if size.get('value', None) is not None:   size = size['value']  return {k: size[k] for k in ('width', 'height')}def get_window_position(self, windowHandle='current'):  """  Gets the x,y position of the current window.  :Usage:   driver.get_window_position()  """  if self.w3c:   if windowHandle != 'current':    warnings.warn("Only 'current' window is supported for W3C compatibile browsers.")   position = self.get_window_rect()  else:   position = self.execute(Command.GET_WINDOW_POSITION,         {'windowHandle': windowHandle})['value']  return {k: position[k] for k in ('x', 'y')}

2.0 獲取窗口句柄

handle = driver.current_window_handle #獲取當前窗口句柄handles = driver.window_handles #獲取所有窗口句柄

切換句柄可以使用

dr.switch_to.window(handle) #其中handle為獲取到的窗口句柄

假設handles為獲取到的所有窗口,則handles為一個list,可使用訪問list的方法讀取句柄。

dr.switch_to.windows(handles[0]) #切換到第一個窗口的句柄dr.switch_to.windows(handles[-1]) #切換到最新窗口的句柄

以上這篇Python+selenium 獲取瀏覽器窗口坐標、句柄的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 全黄裸片武则天一级第4季 偿还电影免费看 | 1314av| 视频久久免费 | 精品中文字幕在线播放 | 97超级碰碰人国产在线观看 | 欧产日产国产精品99 | 国产88久久久国产精品免费二区 | 日本在线视频二区 | xnxx 日本19 | 欧美黄色一级片在线观看 | 又黄又爽免费无遮挡在线观看 | 永久在线观看电影 | 蜜桃av鲁一鲁一鲁一鲁 | 亚洲第一页夜 | 国产成人免费精品 | 欧美乱论| 一边吃奶一边插下面 | 国产精品野外av久久久 | 黄色视屏免费在线观看 | 黄色免费av网站 | 欧美videofree性欧美另类 | 亚洲视频综合网 | 毛片在线不卡 | 久久久成人免费视频 | 国产午夜三级一区二区三桃花影视 | 91网站链接 | 午夜视频在线看 | 午夜看毛片 | 久久狂草 | 牛牛a级毛片在线播放 | 色玖玖综合 | 色婷婷av一区二区三区久久 | 色99久久| 精品国产91久久久久久浪潮蜜月 | 久久综合久久综合久久 | 91精品片| 国产亚洲精品久久久久久久久久 | 斗罗破苍穹在线观看免费完整观看 | 国产九色91 | 亚洲免费观看视频 | 亚洲一区二区中文字幕在线观看 |