# -*- coding: utf-8 -*-
from seleniumimport webdriver
import os
#得到IE驱动的地址
dir = os.path.dirname(__file__)
# dir得到的是python01.py文件所在的位置
ie_driver_path = dir +"\IEDriverServer.exe"
print ie_driver_path
driver = webdriver.Ie(ie_driver_path)
driver.implicitly_wait(30)
driver.maximize_window()
driver.get("https://www.baidu.com/")
search_filed = driver.find_element_by_name("wd")
search_filed.clear()
search_filed.send_keys(u"炫彩流萤ying")
search_filed.submit()
products = driver.find_element_by_xpath("//h3[@class='t']/a")
print products.text
小知识:
from selenium.webdriver.common.by import By
引入By.
driver.find_element_by_name("wd") 可以写成 driver.find_element(By.NAME, "wd")
网友评论