莫愁前路无知己,天下谁人不识君。。。。

python+selenium------一个实例关于---frame+frame+弹窗

上一篇 / 下一篇  2017-11-22 14:29:05 / 个人分类:测试技巧

偶然看到网友的求助,一个网站中的元素定位:frame下面有frame,frame中有弹窗,弹窗中还有frame,最奇怪的是id,name都一样。。。看实例:
 #coding: utf-8
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get("http://www.kaow.cn/index.html")
driver.maximize_window()
driver.find_element_by_id('user').send_keys('15807550000')
driver.find_element_by_id('pwd').send_keys('123456')
driver.find_element_by_id('login').click()
time.sleep(2)
driver.switch_to.frame('ifContent')
driver.find_element_by_id('create-exam').click()
time.sleep(2)
driver.switch_to.default_content()
driver.switch_to.frame('ifContent_tc')
driver.find_element_by_id('exam-name').send_keys('math1243')
time.sleep(1)
driver.find_element_by_id('next-step').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@id="subjects-content"]/div[1]/div[1]').click()
time.sleep(1)
driver.find_element_by_xpath('/html/body/div[4]/div[2]').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@id="subjects-content"]/div[1]/div[2]/div/span').click()
time.sleep(1)
driver.find_element_by_xpath('/html/body/div[5]/div[1]/div[1]').click()
time.sleep(1)
driver.find_element_by_id('next-step').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@id="add-school"]').click()
time.sleep(2)
driver.switch_to.default_content()
方法一
frame. = driver.find_element_by_css_selector('iframe[src="infoManager/add-exam-school.html"]')
driver.switch_to.frame(frame)
driver.find_element_by_xpath('//*[@id="school-list"]/div[1]/input').click()
方法二
#js = '$("iframe[src=\'infoManager/add-exam-school.html\']").contents().find("school-list input[type=\'checkbox\']").eq(0).attr("checked","true")'
#driver.execute_script(js) #选中第一项
注:主要是最后面的frame中frame,其它的很简单。功能补充:
#js = '$("iframe[src=\'infoManager/add-exam-school.html\']").contents().find("#school-list input[type=\'checkbox\']:even").attr("checked","true")'  # 选中基数项
#js = '$("iframe[src=\'infoManager/add-exam-school.html\']").contents().find("#school-list input[type=\'checkbox\']").attr("checked","true")'  # 全选
#driver.execute_script(js)
#time.sleep(1)
#js2 = '$("iframe[src=\'infoManager/add-exam-school.html\']").contents().find("#school-list input[type=\'checkbox\']").removeAttr("checked")'  # 取消全选
#driver.execute_script(js2)

TAG: frame中frame Selenium selenium

引用 删除 小幼稚园   /   2017-12-02 15:01:47
5
 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar