表单切换,下拉框,时间等待

匿名 (未验证) 提交于 2019-12-02 23:47:01

切换iframe表单:b.switch_to_frame(iframe)

返回上级表单:b.switch_to_default_content()

切换表单前找到表单:iframe_ele = b.find_element_by_id('表单元素')

# coding:utf-8import osfrom time import sleepfrom selenium import webdriverfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium.webdriver.support.ui import Select#表单切换b=webdriver.Chrome()#b.implicitly_wait(10)b.maximize_window()b.get('file:///D:/tk/ui/Demo/iframeDemo.html')#b.find_element_by_name('t').send_keys('ttttt')#切换iframe表单iframe_ele = b.find_element_by_id('if')b.switch_to.frame(iframe_ele)b.find_element_by_id('kw').send_keys('rrrrr')b.find_element_by_id('su').click()#返回上级表单b.switch_to_default.content()b.find_element_by_name('t').clear()b.find_element_by_name('t').send_keys('test')sleep(3)b.quit()下拉菜单处理:fromselenium.webdriver.support.uiimport Select使用值定位:Select(x1).select_by_value('10.29')使用索引定位:Select(x1).select_by_index(2),从0开始使用Ite值定位:Select(x1).select_by_visible_text('UPS Next Day Air ==> $12.51')

select_ele = b.find_element_by_id('ShippingMethod')
Select(select_ele).select_by_value('8.34')
Select(select_ele).select_by_index(3)
Select(select_ele).select_by_visible_text('USPS First Class ==> $3.20')

等待时间隐时等待:全局等待时间,作用于整个浏览器始末b.implicitly_wait(10)显示等待:步骤等待时间,只作用与某一元素使用 WebDriverWait() + until() + expected_conditions或者lambda匿名函数实现强制等待:脚本某个位置强制等待设置时间from time import sleepsleep(5)

btn_ele = WebDriverWait(b,10,0.5).until(lambda b:b.find_element_by_id('su'))
btn_ele = WebDriverWait(b,10,0.5).\
until(EC.presence_of_element_located(((By.ID,'su'))))
btn_ele.click()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!