Python selenium полный экран

How to get window size, resize or maximize window using Selenium WebDriver

Selenium WebDriver supports getting the browser window size, resizing and maximizing window natively from its API, no JavaScript injections like window.resizeTo(X, Y); are necessary any more. Below shows the examples on how to achieve this in Selenium WebDriver C#, Ruby and Python bindings.

Ruby

In Ruby binding, window size can be retrieved from method driver.manage.window.size , which is a type of struct Selenium::WebDriver::Dimension defined here. To resize a window, one solution is to create a new Dimension object and assign it to property driver.manage.window.size . Alternatively, Ruby binding has provided a driver.manage.window.resize_to() method, which is equivalent to #size= , but accepts width and height arguments according to API here.

Environment Tested:
Mac OS Sierra, Ruby 2.3.1p112, Selenium 3.0.5, ChromDriver 2.26, GeckoDriver 0.13
Firefox 50.1, Chrome 55, PhantomJS 1.9.8

Example

require 'selenium-webdriver' # get initial window size driver = Selenium::WebDriver.for :firefox puts driver.manage.window.size # set window size using Dimension struct target_size = Selenium::WebDriver::Dimension.new(1024, 768) driver.manage.window.size = target_size puts driver.manage.window.size # resize window driver.manage.window.resize_to(480, 320) puts driver.manage.window.size # maximize window driver.manage.window.maximize puts driver.manage.window.size driver.quit

Output

C#

Similarly in C# binding, a browser window’s size can be found out using driver.Manage().Window.Size property. The same IWindow interface also defines method Maximize() for maximizing the window. Although this interface doesn’t provide a function to resize window directly like Ruby binding, it can be done by setting the Size property using System.Drawing.Size object 1 .

Environment Tested:
Windows 7, Selenium 2.39.0, Firefox 26.0

Example

using System; using System.Drawing; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; namespace BrowserWindowSizeApp  internal class Program  internal static void Main(string[] args)  // get initial window size IWebDriver driver = new FirefoxDriver(); Console.WriteLine(driver.Manage().Window.Size); // set window size driver.Manage().Window.Size = new Size(480, 320); Console.WriteLine(driver.Manage().Window.Size); // maximize window driver.Manage().Window.Maximize(); Console.WriteLine(driver.Manage().Window.Size); driver.Quit(); > > >

Output

Python

Unlike C# and Ruby bindings, Python binding doesn’t offer properties to get/set window size, all get/set/maximize actions are available using methods defined in selenium.webdriver.remote.webdriver.

Environment Tested:
Window 7, Python 2.7, Selenium 2.40.0, Firefox 26.0

Example

from selenium import webdriver # get initial window size driver = webdriver.Firefox() print driver.get_window_size() # set window size driver.set_window_size(480, 320) print driver.get_window_size() # maximize window driver.maximize_window() print driver.get_window_size() driver.quit()

Output

Comparison

Get window size
Ruby driver.manage.window.size
C# driver.Manage().Window.Size;
Python driver.get_window_size()
Set window size
Ruby size = Selenium::WebDriver::Dimension.new(width, height)
driver.manage.window.size = size
C# System.Drawing.Size windowSize = new System.Drawing.Size(width, height);
driver.Manage().Window.Size = windowSize;
Python
Resize window
Ruby driver.manage.window.resize_to(width, height)
C#
Python driver.set_window_size(width, height)
Maximize window
Ruby driver.manage.window.maximize
C# driver.Manage().Window.Maximize();
Python driver.maximize_window()

Источник

How to set browser in fullscreen in Selenium Python?

To set browser in a fullscreen window in Selenium Python, you can use fullscreen_window() function of the webdriver object.

Call full_screen_window() function on the driver object, and pass no arguments to the function.

In this tutorial, you will learn how to set the browser window in fullscreen in Selenium Python.

Example

In the following example, we initialize a Chrome webdriver, and set its window size to fullscreen.

Python Program

from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.chrome.service import Service as ChromeService import time # Setup chrome driver service = ChromeService(executable_path=ChromeDriverManager().install()) driver = webdriver.Chrome(service=service) # Set window to full screen driver.fullscreen_window() # Setting a delay so that we can see the browser window time.sleep(5) # Close the driver driver.quit()

Browser window screenshot

Python Selenium - Driver / Browser Fullscreen Window

Summary

In this Python Selenium tutorial, we learned how to set the browser to a fullscreen window, using fullscreen_window() function.

Источник

Python selenium полный экран

  • add_cookie driver method – Selenium Python
  • back driver method – Selenium Python
  • close driver method – Selenium Python
  • create_web_element driver method – Selenium Python
  • delete_all_cookies driver method – Selenium Python
  • delete_cookie driver method – Selenium Python
  • execute_async_script driver method – Selenium Python
  • execute_script driver method – Selenium Python
  • forward driver method – Selenium Python
  • fullscreen_window driver method – Selenium Python
  • get_cookies driver method – Selenium Python
  • get_log driver method – Selenium Python
  • get_screenshot_as_base64 driver method – Selenium Python
  • get_screenshot_as_file driver method – Selenium Python
  • get_screenshot_as_png driver method – Selenium Python
  • get_window_position driver method – Selenium Python
  • get_window_rect driver method – Selenium Python
  • get_window_size driver method – Selenium Python
  • implicitly_wait driver method – Selenium Python
  • maximize_window driver method – Selenium Python
  • minimize_window driver method – Selenium Python
  • quit driver method – Selenium Python
  • refresh driver method – Selenium Python
  • set_page_load_timeout driver method – Selenium Python
  • set_script_timeout driver method – Selenium Python
  • set_window_position driver method – Selenium Python
  • set_window_rect driver method – Selenium Python
  • current_url driver method – Selenium Python
  • current_window_handle driver method – Selenium Python
  • page_source driver method – Selenium Python
  • title driver method – Selenium Python

Element Methods

  • is_displayed() element method – Selenium Python
  • is_enabled() element method – Selenium Python
  • get_property() element method – Selenium Python
  • get_attribute() element method – Selenium Python
  • send_keys() element method – Selenium Python
  • click() element method – Selenium Python
  • clear() element method – Selenium Python
  • screenshot() element method – Selenium Python
  • submit() element method – Selenium Python
  • value_of_css_property() element method – Selenium Python
  • location element method – Selenium Python
  • screenshot_as_png element method – Selenium Python
  • parent element method – Selenium Python
  • size element method – Selenium Python
  • tag_name element method – Selenium Python
  • text element method – Selenium Python
  • rect element method – Selenium Python
  • screenshot_as_base64 element method – Selenium Python

Project Examples

Источник

selenium maximize

Maximization of a web browser through the Web Driver (Python selenium) is very easy. In short, all you have you have to do is start the browser and call the maximize_window().

(Selenium is a Python module that uses a web driver to control a web browser for you)

Related course:

selenium

selenium maximize

Before you start, make sure you have the right Web Driver installed for your Web Browser. For Firefox that’s GeckoDriver, For Chrome that’s ChromeDriver and so on.

Besides installing the Web Driver, you need to install the Python selenium module. The selenium module can be installed using the operating systems package manager or pip.

The example below opens the web browser and maximizes it. This is done in a few steps.

from selenium import webdriver
import time

driver = webdriver.Firefox()
driver.maximize_window()
time.sleep(5)

driver.get(«https://www.python.org»)

selenium maximize

First import webdriver and the time module. These are required for interacting with the Web Driver.

from selenium import webdriver
import time

Then open your web browser, for instance, firefox with webdriver.Firefox() and maximize the window with the call maximize_window().

driver = webdriver.Firefox()
driver.maximize_window()
time.sleep(5)

Источник

Python selenium полный экран

  • add_cookie driver method – Selenium Python
  • back driver method – Selenium Python
  • close driver method – Selenium Python
  • create_web_element driver method – Selenium Python
  • delete_all_cookies driver method – Selenium Python
  • delete_cookie driver method – Selenium Python
  • execute_async_script driver method – Selenium Python
  • execute_script driver method – Selenium Python
  • forward driver method – Selenium Python
  • fullscreen_window driver method – Selenium Python
  • get_cookies driver method – Selenium Python
  • get_log driver method – Selenium Python
  • get_screenshot_as_base64 driver method – Selenium Python
  • get_screenshot_as_file driver method – Selenium Python
  • get_screenshot_as_png driver method – Selenium Python
  • get_window_position driver method – Selenium Python
  • get_window_rect driver method – Selenium Python
  • get_window_size driver method – Selenium Python
  • implicitly_wait driver method – Selenium Python
  • maximize_window driver method – Selenium Python
  • minimize_window driver method – Selenium Python
  • quit driver method – Selenium Python
  • refresh driver method – Selenium Python
  • set_page_load_timeout driver method – Selenium Python
  • set_script_timeout driver method – Selenium Python
  • set_window_position driver method – Selenium Python
  • set_window_rect driver method – Selenium Python
  • current_url driver method – Selenium Python
  • current_window_handle driver method – Selenium Python
  • page_source driver method – Selenium Python
  • title driver method – Selenium Python

Element Methods

  • is_displayed() element method – Selenium Python
  • is_enabled() element method – Selenium Python
  • get_property() element method – Selenium Python
  • get_attribute() element method – Selenium Python
  • send_keys() element method – Selenium Python
  • click() element method – Selenium Python
  • clear() element method – Selenium Python
  • screenshot() element method – Selenium Python
  • submit() element method – Selenium Python
  • value_of_css_property() element method – Selenium Python
  • location element method – Selenium Python
  • screenshot_as_png element method – Selenium Python
  • parent element method – Selenium Python
  • size element method – Selenium Python
  • tag_name element method – Selenium Python
  • text element method – Selenium Python
  • rect element method – Selenium Python
  • screenshot_as_base64 element method – Selenium Python

Project Examples

Источник

Читайте также:  Нок двух чисел алгоритм питон
Оцените статью