Python+Selenium之常用模块
Posted Amy_Hu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python+Selenium之常用模块相关的知识,希望对你有一定的参考价值。
要用webdriver:from selenium import webdriver
eg: driver = webdriver.Chrome()
driver.maximize_window()
driver.get("http://www.baidu.com")
要用等待:from selenium.webdriver.common.by import By,from selenium.webdriver.support.ui import WebDriverWait,from selenium.webdriver.support import expected_conditions as EC
eg: WebDriverWait(driver,15,0.5).until(EC.presence_of_element_located((By.NAME,"username"))).send_keys("Amy")
要用perform:from selenium.webdriver.common.action_chains import ActionChains
eg: ActionChains(driver).click(driver.find_element_by_id("inputCtrl0")).send_keys(Company).perform()
要操作下拉框:from selenium.webdriver.support.select import Select
eg: Select(driver.find_element_by_xpath("//select[@ng-model=‘accountInfoView.value.communication.code‘]")).select_by_index(2)
要操作键盘:from selenium.webdriver.common.keys import Keys
eg: driver.find_element_by_xpath("//input[@label=‘Postal Code‘]").send_keys(Keys.TAB)
要用系统时间:from datetime import datetime
eg: Account = "TestAccount" + datetime.now().strftime(‘%Y%m%d%H%M%S‘)
要操作Excel:from openpyxl import load_workbook
eg: wb = load_workbook(‘C:Portal_ScriptsTestData/Portal_TestData.xlsx‘)
env = wb[‘Environment‘]
envValue = env.cell(2,1).value
要用sleep:from time import *
eg: sleep(2)
以上是关于Python+Selenium之常用模块的主要内容,如果未能解决你的问题,请参考以下文章
爬虫--Python常用模块之requests,urllib和re