码迷,mamicode.com
首页 > 其他好文 > 详细

selenium 悬浮-下拉列表

时间:2019-09-01 22:04:23      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:wait   不选中   高级   选择   ons   实例   微软   元素   选中   

 

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ES
from selenium.webdriver.common.by import By
import time

from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome()
driver.implicitly_wait(30) # 等待元素存在,命令执行完成

# 访问并搜索
driver.get("http://www.baidu.com")
# web 鼠标操作 -app 触发操作
# 类 TouchActions
# 悬浮 ,双击 ,右键 ,单击 ,拖拽
# 调用方法,存储到行为列表

# 鼠标悬浮
# 实例化 ActionChains
ac = ActionChains(driver)
# 找到要操作的元素
ele = driver.find_element_by_xpath("//div[@id=‘u1‘]//a[@name=‘tj_settingicon‘]")
# 鼠标悬浮
# ac.move_to_element(ele).perform()
# 也可以点击 下
ac.move_to_element(ele).perform()
time.sleep(1)
ac.click(ele).perform()



---------------悬浮 + select
#  检查快捷键  ctrl + shift +c

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ES
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.select import Select

from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome()
driver.implicitly_wait(30) # 等待元素存在,命令执行完成

# 访问并搜索
driver.get("http://www.baidu.com")

# 实例化 ActionChains
ac = ActionChains(driver)
# 找到要操作的元素
ele = driver.find_element_by_xpath("//div[@id=‘u1‘]//a[@name=‘tj_settingicon‘]")
# 鼠标悬浮
# ac.move_to_element(ele).perform()
# 也可以点击 下
ac.move_to_element(ele).perform()
time.sleep(1)
ac.click(ele).perform()

# 悬浮列表元素操作
loc = (By.XPATH,"//a[text()=‘高级搜索‘]")
# 等到元素出现
WebDriverWait(driver,10).until(ES.visibility_of_element_located(loc))
# 点击元素
driver.find_element(*loc).click()

WebDriverWait(driver,10).until(ES.visibility_of_element_located((By.XPATH,"//select[@name=‘ft‘]")))
# Select
# 实例化 select 类
s = Select(driver.find_element_by_xpath("//select[@name=‘ft‘]"))
# 3种选择option 的方法
# value 属性,index下标 ,文本内容
s.select_by_value("rtf")
time.sleep(2)
s.select_by_index(1)
time.sleep(2)
s.select_by_visible_text("微软 Powerpoint (.ppt)")


# select 类下面也有不选中的方法

selenium 悬浮-下拉列表

标签:wait   不选中   高级   选择   ons   实例   微软   元素   选中   

原文地址:https://www.cnblogs.com/yago/p/11443694.html

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