from selenium import webdriverimport unittestimport timefrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.common.exceptions import TimeoutException, NoSuchElementException# firfoxdriver 为 你的firefox安装路径import repsd1 = []k = open(r'C:\Users\Administrator\PycharmProjects\untitled\1\zidonghua\zil', encoding='utf-8')for i in k: i=i.strip('\n') psd1.append(i)mb={psd1[14]:psd1[17],psd1[20]:psd1[23],psd1[26]:psd1[29]}print(psd1)class GloryRoad(unittest.TestCase): def setUp(self): self.driver=webdriver.Firefox(executable_path='C:\geckodriver') def testSoGou(self): kk = psd1[2] pwd=psd1[5] driver=self.driver driver.get('https://appleid.apple.com/#!&page=signin') try: driver.implicitly_wait(3)#智能等待3秒 driver.switch_to.frame('aid-auth-widget-iFrame') driver.find_element_by_id("appleId").send_keys(kk) driver.find_element_by_id("pwd").send_keys(pwd) driver.find_element_by_id('sign-in').click() print('成功') except : print('没有成功') time.sleep(3) kk1=driver.find_element_by_id('alertInfo').text if '回答您的安全提示问题以继续。' in kk1 : print('进入验证阶段') else: print('失败') exit() k2 = driver.find_elements_by_class_name('form-cell') try: driver.implicitly_wait(3) driver.find_element_by_xpath('html/body/div[2]/div/div/div[1]/div[2]/step-challenge-security-questions/idms-step/div/div/div/div/div/div[1]/div/div/idms-textbox/idms-error-wrapper/div/input').send_keys(mb.get(k2[0].text)) driver.find_element_by_xpath('html/body/div[2]/div/div/div[1]/div[2]/step-challenge-security-questions/idms-step/div/div/div/div/div/div[2]/div/div/idms-textbox/idms-error-wrapper/div/input').send_keys(mb.get(k2[1].text)) driver.find_element_by_xpath('html/body/div[2]/div/div/div[1]/div[3]/div/button[2]').click() except: print('没有成功,获取不到数据') def tearDown(self): pass # self.driver.quieif __name__=='__main__': unittest.main()