Control browser work with selenium webdriver

One install and start python

(Omitted) IDE recommends using vscode or pycharm

Second install selenium


Three download according to the webdriver driver

     1. chromedriver download address: http://chromedriver.storage.googleapis.com/index.html 2.
     Firefox driver geckodriver download address: https://github.com/mozilla/geckodriver/releases/
     3. IE driver IEdriver Download address: http://www.nuget.org/packages/Selenium.WebDriver.IEDriver/

Note: 1) After downloading and decompressing, send chromedriver.exe , geckodriver.exe , Iedriver.exe to the Python installation directory. The installation
   is not clear In the case of the directory, cmd executes the path view.

      2) On the download page, pay attention to find the driver version that matches the browser. Take chrome as an example, look at the contents of the notes.txt file in the directory.



Four call different browser methods

### chrome
from selenium import webdriver
browser = webdriver.Chrome()
browser.get('http://www.baidu.com/')
### firefox
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.baidu.com/')
### ie
from selenium import webdriver
browser = webdriver.Ie()
browser.get('http://www.baidu.com/')

Five Code Examples

from selenium import webdriver
# browser = webdriver.Firefox()
# browser = webdriver.Ie()
browser = webdriver.Chrome()
browser.get('http://inventwithpython.com')
try:
    elem = browser.find_element_by_class_name('nav-link')
    print('Found <%s> element with that class name!' % (elem.tag_name))
except:
    print('Was not able to find an element with that name.')

Guess you like

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