__author__ = 'Administrator'
# coding: utf-8
from selenium import webdriver
import time
import os
import pdb
from selenium import selenium
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
# if 'HTTP_PROXY'in os.environ: del os.environ['HTTP_PROXY']
browser = webdriver.Firefox() # open Chrome or Firefox
browser.get("http://www.******.com/") # load www.cmall.com
time.sleep(2) # let the page load
print('title of current page is %s' %(browser.title))
print('url of current page is %s' %(browser.current_url))
time.sleep(2)
browser.find_element_by_xpath(".//*[@id='userLogin']/a[1]/span").click()
'''
XX = browser.find_element_by_tag_name("iframe")
browser.switch_to.frame(XX)
browser.find_element_by_id('usernameLogin').send_keys('*****')
browser.find_element_by_id('passwordLogin').send_keys('*******')
time.sleep(2)
browser.find_element_by_id('btnLoginLocal').click()
'''
'''
# 这种方法也可以的,就是太笨了,真难看
browser.get("http://www.******.com/login-quick.html")
browser.find_element_by_id('btnLogin').click()
time.sleep(5)
browser.find_element_by_id('usernameLogin').send_keys('*******')
browser.find_element_by_id('passwordLogin').send_keys('*******')
browser.find_element_by_id('btnLoginLocal').click()
'''
# def changeTostartOrderWindow(browser):
# yuding = browser.find_element_by_xpath('html/body/div[5]/div[3]/div[2]/div/iframe')
# browser.find_elements_by_class_name('pdb-contentframe')
# 原来无需先定位上层class,原来不支持直接yuding=browser.find这种写法
browser.find_element_by_tag_name('iframe')
yuding = browser.find_element_by_tag_name('iframe')
'''
text = yuding.get_attribute()
print("iframe's id is" %text)
'''
# text = yuding.find_element_by_tag_name('iframe').get_attribute('id')
# yuding = browser.FindElements('iframe_1453206880881') 动态的iframe无法取到固定id
browser.switch_to_frame(yuding) # 之前用的iframe,怎么也取不到
time.sleep(10)
# browser.switch_to().frame(yuding)
browser.find_element_by_id('btnLogin').click()
time.sleep(10)
# yufeng = browser.find_element_by_name('iframe_1453204183258')
# browser.switch_to.frame(yufeng) 方法么写对啊,不是点,而是下划线
browser.find_element_by_id('usernameLogin').send_keys('*******')
browser.find_element_by_id('passwordLogin').send_keys('******')
browser.find_element_by_id('btnLoginLocal').click()
# pass
# 切换框架方法-结束
#def changeToDefaultIframe(browser):
browser.switch_to.default_content();
#pass