Python+Selenium之經常使用模塊

要用webdriver:from selenium import webdriverweb

eg: driver = webdriver.Chrome()
      driver.maximize_window()
      driver.get("http://www.baidu.com")ui

要用等待:from selenium.webdriver.common.by import By,from selenium.webdriver.support.ui import WebDriverWait,from selenium.webdriver.support import expected_conditions as ECcode

eg: WebDriverWait(driver,15,0.5).until(EC.presence_of_element_located((By.NAME,"username"))).send_keys("Amy")orm

要用perform:from selenium.webdriver.common.action_chains import ActionChainsip

eg: ActionChains(driver).click(driver.find_element_by_id("inputCtrl0")).send_keys(Company).perform()element

要操做下拉框:from selenium.webdriver.support.select import Selectget

eg: Select(driver.find_element_by_xpath("//select[@ng-model='accountInfoView.value.communication.code']")).select_by_index(2)input

要操做鍵盤:from selenium.webdriver.common.keys import Keysselenium

eg: driver.find_element_by_xpath("//input[@label='Postal Code']").send_keys(Keys.TAB)it

要用系統時間: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_Scripts\TestData/Portal_TestData.xlsx')
      env = wb['Environment']
      envValue = env.cell(2,1).value

要用sleep:from time import *

eg: sleep(2)

相關文章
相關標籤/搜索