码迷,mamicode.com
首页 > 编程语言 > 详细

Python+Selenium之常用模块

时间:2019-04-04 15:44:57      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:max   NPU   path   cli   use   key   time   expected   ftime   

要用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)

Python+Selenium之常用模块

标签:max   NPU   path   cli   use   key   time   expected   ftime   

原文地址:https://www.cnblogs.com/AmyHu/p/10655116.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!