from selenium import webdriver
from time import sleep
class TestCase(object):
def __init__(self):
self.driver = webdriver.Chrome()
self.driver.get('http://sahitest.com/demo/framesTest.htm')
self.driver.maximize_window()
def test(self):
top = self.driver.find_element_by_name('top')
self.driver.switch_to.frame(top)
self.driver.find_element_by_xpath('/html/body/table/tbody/tr/td[1]/a[1]').click()
sleep(1)
# 退出第一个frame
self.driver.switch_to.default_content()
sleep(1)
# 找到第二个frame
se = self.driver.find_element_by_xpath('/html/frameset/frame[2]')
self.driver.switch_to.frame(se)
self.driver.find_element_by_xpath('/html/body/table/tbody/tr/td[1]/a[2]').click()
if __name__ == '__main__':
case = TestCase()
case.test()
sleep(2)
case.driver.quit()