首页 > 编程语言 > 详细

sel+python 基础

时间:2021-06-15 16:16:59      阅读:15      评论:0      收藏:0      [点我收藏+]

1. import packages

   from selenium import webdriver

   from selenium.webdriver.common.keys import Keys

 

2. 元素操作

   清空文本

   elm.clear()

   输入文本

   elm.send_keys(‘xxxx‘)

   上传文件

   ------type = ‘file‘-----

   elm.send_keys(r‘/locate‘)

  执行js

  driver.execute_script()

  切换浏览器

  - 获取所有的浏览器窗口:wins = driver.window_handles

  - driver.switch_to.wins(wins[-1])

     driver.switch_to.wins(wins[0])

  切换iframe

  - 

  鼠标操作

  - from selenium.webdriver.common.action_chains import ActionChains

  - ActionChains(driver).move_to_element(elm).perform()

  - ActionChains(driver).move_to_element(elm).click().perform() 

 etc

 拖拽行为

  - action = ActionChains(driver)

    action.move_to_element(elm).click_and_hold().move_by_offset(x,y).release().perform()

 隐式等待

 - driver.implicitly_wait(x)

 如果在x之前就加载出来,则不再等待

 如果超过x未加载出来,则抛超时异常

 显示等待

 - from selenium.webdriver.common.by import By

    from selenium.webedriver.support.wait import WebdriverWait

    WebdriverWait(driver,15).until(EC.presence_of_element_located((By.Xpath,‘loc‘)))

   隐式等待是针对所有元素

   显示等待只针对特定元素

 

sel+python 基础

原文:https://www.cnblogs.com/lutong1989/p/14884293.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!