Python+Selenium learning -- browser settings

Scenes

There are two common uses for setting the size of the browser window:

  • Running the use case under a unified browser size can be easily combined with some image comparison-based tools to improve the flexibility and universal applicability of testing. For example, it can be combined with sikuli and use sikuli to operate flash;
  • Visit the test site under different browser sizes, take a screenshot of the test page and save it, and then observe or use an image comparison tool to evaluate the front-end style of the tested page. For example, you can set the browser to the size of the mobile terminal (320x480), and then visit the mobile site to evaluate its style;

code

#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
Created on 2018/5/9 9:55
@author: Jeff Lee
@file: browser window settings.py
'''
from selenium import  webdriver
import time

print('Open browser')
cl = webdriver.Firefox()
time.sleep(2)

print('window maximized')
cl.maximize_window()

time.sleep(2)
print('window minimized')
cl.minimize_window()

time.sleep(2)
print('window settings')
cl.set_window_size(600,300)

print('close the browser')
cl.quit()

 Discuss

Webdriver provides a lot of interfaces to adjust the browser window, such as set_window_position (set or get the position of the browser). In general, these functions are not commonly used.

 

Reference http://www.cnblogs.com/nbkhic/tag/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326357741&siteId=291194637