Python+Selenium之常用模块

2019/04/04 15:29
阅读数 15

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

要用sleep:from time import *

eg: sleep(2)

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部