本機(jī)環(huán)境介紹
Python版本
(py3env) C:\Users\XXX\iCloudDrive\PycharmProjects\SAT>python -V
Python 3.6.2
Java版本
C:\Users\XXX>java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
Selenium版本(3.7.0)
(py3env) C:\Users\XXX\iCloudDrive\PycharmProjects\SAT>pip show selenium
Name: selenium
Version: 3.7.0
Summary: Python bindings for Selenium
Python-Selenium是如何啟動(dòng)Internet Explorer瀏覽器的
# -*- coding: utf-8 -*-
import os
from selenium import webdriver
if __name__ == '__main__':
CURRENT_PATH = os.path.join(os.path.dirname(__file__), '../resource') # 當(dāng)前路徑
IE_DRIVER = os.path.join(CURRENT_PATH, 'IEDriverServer.exe') # ie driver路徑
driver = webdriver.Ie(executable_path=IE_DRIVER)
driver.get(url="https://www.baidu.com/")
driver.find_element_by_id('kw').send_keys('selenium')
driver.quit()
Java-Selenium是如何啟動(dòng)Internet Explorer瀏覽器的
package test;
import java.nio.file.Path;
import java.nio.file.Paths;
class Test {
public static void main(String[] args) {
String CURRENT_PATH = System.getProperty("user.dir");
Path path = Paths.get(CURRENT_PATH, "../resource", "IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", path.toString());
WebDriver driver = new InternetExplorerDriver();
driver.get("https://www.baidu.com/");
driver.findElement(By.id("kw")).sendKeys("selenium");
driver.quit();
}
}
總結(jié)
我們知道,在啟動(dòng)IE瀏覽器都需要加載IEDriverServer.exe
驅(qū)動(dòng),以上兩個(gè)方法都是通過(guò)代碼的方式加到系統(tǒng)環(huán)境變量中虑瀑,我們同樣可以通過(guò)其他方法添加赫冬,如:Windows:計(jì)算機(jī)=》屬性=》高級(jí)系統(tǒng)設(shè)置=》高級(jí)=》環(huán)境變量
, linux設(shè)置環(huán)境變量方法就很多了,可以自行百度聘萨,google
IEDriverServer.exe
一定要用32位的晨仑,下載地址
PS:下載與Selenium版本相匹配的exe文件哦
==> 點(diǎn)擊我的博客