In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)05/31 Report--
Editor to share with you what are the common methods of Selenium to control the browser, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!
How did Selenium get here?
The word Selenium means the chemical element selenium (Se). In the field of software testing, it is the absolute benchmark for automated testing open source projects. This name is also fastidious, in the field of software testing at that time and even today, the share of QTP (UFT) is very high. Quick Test Professional is developed by Mercury, which is naturally mercury (Hg). In biology, studies have found that selenium has an antagonistic effect on mercury, that is, selenium grams of mercury. The purpose of the name Selenium is self-evident.
Selenium controls the operation of the browser
Selenium is a tool for testing Web applications. The Selenium test runs directly in the browser, just like a real user is working on it. Supported browsers include IE (7, 8, 9, 10, 11), Mozilla Firefox,Safari,Google Chrome,Opera, etc.
The main features of this tool include: testing compatibility with browsers-testing your application to see if it works well on different browsers and operating systems. Test system function-create regression tests to check software functions and user requirements. Supports automatic recording of actions and automatic generation of test scripts in .net, Java, Perl and other languages.
Sometimes we want to have the browser open at a certain size, let the access page run at that size, or control the browser for backward and forward operations, and so on.
Today, we mainly introduce some common properties and methods of browser control, most of which are concentrated in the selenium.webdriver.remote.webdriver class. No matter which browser they use, they all inherit from the remote.webdriver class and use the same method properties.
Here are a few examples of controlling browsers.
Control the size of the browser window
Sometimes we want to be able to open it at a certain browser size and let the visited page run at that size. For example, you can set the browser to the mobile size (480 * 800) and then visit the mobile site to evaluate its style; WebDriver provides a set_window_size () method to set the size of the browser.
Second, set dormancy time
Since it takes a few seconds for the page to load after opening the Baidu URL, it is best to wait until the page is loaded before continuing with the next step.
Third, control the browser forward and backward
When browsing the web using the browser, the browser provides back and forward buttons to easily switch between browsed web pages, and WebDriver also provides corresponding back () and forward () methods to simulate the back and forward buttons. The following examples demonstrate the use of these two methods.
Fourth, page refresh
Sometimes after the page operation, the data may not be synchronized in time and need to be refreshed.
5. Page screenshot
Automation use cases are executed by the program, so sometimes the printed error message is not very clear. If you can save the screenshot of the current window when there is an error in the execution of the script, you can see the cause of the error intuitively through the picture. WebDriver provides a screenshot function get_screenshot_as_file () to capture the current window:
It is worth noting that when using the window screenshot feature, the extension of the picture must be pngshots!
6. Close and exit the browser
There are two ways to exit, one is close; and the other is quit.
Close is used to close the current window. When there are more windows open, you can use close to close some windows.
Quit is used to end the process and close all windows.
Summary:
Let's start with a few common attributes:
Current_url: returns the url of the current browser
Title: returns the current page title
Current_window_handler: returns the handle to the current window, which is used when switching multiple windows
Window_handlers: returns the handle to all windows in the current browser.
The following are common ways to control browsers:
Get (url): loads the specified web page
Back () / forward (): the forward and backward buttons corresponding to the browser
Implicitly_wait (time): implicit wait, the wait time, in seconds, before the element is found, in time. Its scope is global, a session only needs to be set once, and any element is thrown if it is not found within a specified time. A separate article will be used to introduce the topic of element waiting, which will not be explained in detail here.
Close (): closes the current window
Quit (): close the entire browser and all windows will be closed
Refresh (): refresh the web page
Get_screenshot_as_file (filename): save the screenshot of the browser to a png file. Note here that filename needs to be a complete path, such as / Users/jack/Downloads/screenshot.png.
The unit of set_window_position is pixel, which sets the location of the browser. Get_window_position () can get the current location of the browser
Set_window_size (width,height, windowHandle='current'): the unit of width,height is pixels, which sets the length and width of the browser. Get_window_size () can get the size of the browser
Maximize_window (): maximize the window
These are all the contents of this article entitled "what are the common ways to control browsers with Selenium?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.