- The basic method of operation of the browser
- open the Web page
- Selenium introduced into the module from the webdrive
- Open a browser (firefox)
- Open the Web page (www.baidu.com)
-
# Import webdriver module from the Selenium Import webdriver # open the browser Driver = webdriver.Firefox () # Driver = webdriver.Ie () # Driver = webdriver.Chrome () # open Baidu Home driver.get ( " HTTPS: // the WWW. baidu.com " )
- Set Sleep Time
- Introducing python comes time module
- It is expected to open the page of time needed to set the sleep time
-
# Import webdriver module from the Selenium Import webdriver # import the time module Import time # to open the browser Driver = webdriver.Firefox () # open Baidu Home driver.get ( " https://www.baidu.com " ) # Set the sleep time, can also be a decimal seconds the time.sleep (5) # expected time required to load the page
- Refresh page
- For synchronizing the page content
-
from Selenium Import the webdriver Import Time Driver = webdriver.Firefox () driver.get ( " https://www.baidu.com " ) # Set sleep time, may be a decimal seconds the time.sleep (. 5) # Wait after five seconds to refresh the page driver.refresh ()
- Page switching
- Return to the previous page or the next page (the browser to the left, right arrow)
-
from Selenium Import the webdriver Import Time Driver = webdriver.Firefox () driver.get ( " https://www.baidu.com " ) the time.sleep ( . 8 ) driver.get ( " https://www.duba.com " ) the time.sleep ( 10 ) # Back driver.back () the time.sleep ( 10 ) # switch to the next driver.forward ()
- Set window size
- Maximize the browser window is set, or set a fixed size window
-
from Selenium Import the webdriver Import Time Driver = webdriver.Firefox () driver.get ( " https://www.baidu.com " ) the time.sleep ( . 3 ) # Set the browser window of fixed size (540. * 960) driver.set_window_size (540,960 ) the time.sleep ( 3 ) # will maximize the browser window driver.maximize_window ()
- To open the web page screenshots
-
from Selenium Import the webdriver Import Time Driver = webdriver.Firefox () driver.get ( " https://www.baidu.com " ) the time.sleep ( . 3 ) # Set save path + file name + extension driver.get_screenshot_as_file ( " E : \\ b1.png " )
-
- drop out
- close: Close the current window
- quit: the end of the process, close all windows
- Use quit at the end of the test, the C drive recyclable temporary files
-
from the Selenium Import webdriver Import Time Driver = webdriver.Firefox () driver.get ( " https://www.baidu.com " ) the time.sleep ( 3 ) # quit to end the process, close all windows driver.quit ()
- open the Web page
The basic operation of selenium webdrive browser
Guess you like
Origin www.cnblogs.com/Arcy/p/11070263.html
Ranking