Python+Selenium+FireFox Browserwebdriver Installed Using Example Linux Environment

Automation of python selenium

  1. Install Selenium
pip install selenium
  1. Browser Drive Install
打开网页检查最新版本然后下载或修改最新的版本号下载https://selenium-python.readthedocs.io/installation.html#drivers
wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
tar -xvzf geckodriver-v0.26.0-linux64.tar.gz
chmod +x geckodriver
sudo mv geckodriver /usr/bin/
  1. Install test code
from selenium import webdriver
import time

brower = webdriver.Firefox()
brower.get("http://www.baidu.com")

brower.find_element_by_id('kw').send_keys('selenium')
brower.find_element_by_id('su').click()

time.sleep(3)
print(brower.current_url)

brower.quit()
  1. Common Errors
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

OrganisationgeckodriverNo installation was successful.
You can also specify a directory, for example by specifying that it is under the current path.

brower = webdriver.Firefox(executable_path='./geckodriver')
  1. No Heading Parameters
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
import time
options = Options()
options.add_argument('-headless') # 无头参数
brower = webdriver.Firefox(firefox_options=options)
brower.get("http://www.baidu.com")

brower.find_element_by_id('kw').send_keys('selenium')
brower.find_element_by_id('su').click()

time.sleep(3)
print(brower.current_url)
brower.quit()

未经允许不得转载:萌萌Apprentissage » Python+Selenium+FireFox Browserwebdriver Installed Using Example Linux Environment

Like (0) 打赏

Comments 0

Protected with IP Blacklist CloudIP Blacklist Cloud
  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

//下一个脚本特效
//下一个脚本