python selenium 实战涉及很多知识点

1、iframe的切入和切出

#切入
driver.switch_to.frame(driver.find_element_by_id('iFrame_1'))
# 切换出来
driver.switch_to.default_content()

  

2、句柄的切入和切出

main_windows = driver.current_window_handle
# 获取主窗口句柄
# main_handle = driver.current_window_handle
''' 指纹采集 '''
# 点击采集指纹 新页面
driver.find_element_by_xpath("//input[@id='button_20']").click()

time.sleep(3)
# url_1 = "http://192.168.14.249/ywbl/jbyw/dzhz/CheckZw/007001007001334/$B/19940403/1560481330594"

# 切换到最小弹出的窗口Windows的最后一个元素
# windows = driver.window_handles
# driver.switch_to.window(windows[-1])

# 切换回主窗口
all_windows = driver.window_handles
print(all_windows)
# 切换进注册页面
for handle in all_windows:
    if handle != main_windows:
        driver.switch_to.window(handle)

        # document.querySelector("#couseText").value='{}';
        js = '''
            document.querySelector('#couseText').value='{}';
            '''.format("申请人未满十六周岁")
        driver.execute_script(js)

        driver.find_element_by_xpath("//input[@id='OKButton']").click()

        rztext = driver.find_element_by_xpath("//span[@id='errorMsg']").get_attribute("value")
        if rztext == '该数据已经做过指纹核验审批!':
            driver.find_element_by_xpath("//input[@value='取 消']").click()

        time.sleep(5)

# 重先定位到主页面,原来窗口
driver.switch_to.window(main_windows)
# 在切换到iframe里面才能找到下面的元素
driver.switch_to.frame(driver.find_element_by_id('iFrame_1'))

  

3、鼠标悬停

action = ActionChains(driver)
# 鼠标移动到该元素上,鼠标悬停,等待下拉框元素可见
ele = driver.find_element_by_xpath("//div[@id='fzgnbtZw']")
action.move_to_element(ele).perform()

  

4、鼠标定位移动点击

site = driver.find_element_by_xpath("//input[@title='输入关键字查询,双击显示前10条记录!']").location_once_scrolled_into_view
site1 = driver.find_element_by_xpath("//input[@title='输入关键字查询,双击显示前10条记录!']").location
windowsSite = driver.get_window_rect()
x,y = -1*site["x"],site1["y"]+windowsSite["y"]+10
time.sleep(1)
print(site,'\n',site1,'\n',windowsSite)
ActionChains(driver).move_by_offset(x,y).context_click().perform()

  

5、填下拉查询输入表使用延迟

driver.find_element_by_xpath(mainPath+"/input[@id='sbmacID']").send_keys("0021")
time.sleep(1)
driver.find_element_by_xpath("//div[@class='form-group']/div/div/div/input[@name='CODEVALUE_sblx']").send_keys("填表机")
time.sleep(1)
driver.find_element_by_xpath("//div[@class='form-group']/div/div/div/input[@id='CODEVALUE_lclxID']").send_keys("内地申请")
time.sleep(1)
driver.find_element_by_xpath("//input[@name='CODEVALUE_xzqh' and @id='CODEVALUE_xzqhID' and @class='form-control zd-input-sm input-sm form-control required']").send_keys("北京市辖区")
time.sleep(1)
driver.find_element_by_xpath("//div[@class='form-group']/div/div/input[@id='sbwzID']").send_keys("广州")

  

 6、alert 弹框确定进行点击处理

# alert 点击弹框确定
Alert(driver).accept()

  

 

posted @ 2019-06-18 11:45  洺剑残虹  阅读(298)  评论(0编辑  收藏  举报