Selenium3: Basic method of manipulating elements

 Source: "Selenium webdriver based on Python source code case"

1. Open the webpage
① The first step: import the webdriver module from selenium
② Open the browser (Ie and Chrome correspond to the following)
③ Open the Baidu website

2. Set sleep

①. Since it takes a few seconds to load the page after opening the Baidu website, it is best to wait until the page is loaded before proceeding to the next step.
②. Import the time module, which comes with Python, so there is no need to download it
. ③. Set the waiting time , the unit is seconds (s), the time value can be a decimal or an integer

3. Page refresh
①. Sometimes after page operation, the data may not be synchronized in time and need to be refreshed again

②. Here you can simulate the page refresh operation, which is equivalent to the refresh button behind the browser input box

4. Page switching
①. When you want to return to the previous page after opening two pages in a browser, it is equivalent to the left arrow button in the upper left corner of the browser
②. After returning to the previous page, you can also switch to the next page. Equivalent to the right arrow button in the upper left corner of the browser

Five, set the window size

①. You can set the browser window size, such as setting the window size to the mobile phone resolution 540*960
②. You can also maximize the window

 


6. Screenshot
①. After opening the website, you can also take a screenshot of the screen
②. After the screenshot, set the specified save path + file name + suffix

 


7. Exit
①. There are two ways to exit, one is close; the other is quit

②.close is used to close the current window. When there are many open windows, you can use close to close some windows
. ③.quit is used to end the process and close all windows
. ④. Finally, to end the test, use quit. quit can recycle the temporary files of the c drive

After mastering the basic operations of the browser, you can start learning element positioning. Element positioning requires a certain HTML basis. If there is no basis, you can press the F12 shortcut key of the browser to first look at the layout of html, and you can understand some first.

 

Guess you like

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