一个练手的网站
自动登陆 密码提交 定位它的余额 其它的大部分我都进了
就是想获取它的球队名 但是总是定位不到给我报了个找不到的错误
如图:
网站的球队名如图:
![图片描述][2]
网站定位的框架如图:
![图片描述][3]
代码如下:
from selenium import webdriver
driver = webdriver.Chrome()
driver.implicitly_wait(10)
driver.set_window_position(10,100)
driver.set_window_size(1280, 700)
driver.get('http://66.133.87.55/')
iframe =driver.find_element_by_name('SI2_mem_index')
driver.switch_to.frame(iframe)
'''点击旧网站'''
test_crown = driver.find_element_by_xpath('//*[@id="oldspan"]')
test_crown.click()
'''账号'''
username = driver.find_element_by_id('username')
username.clear()
username.click()
username.send_keys('testName888')
'''密码'''
userpasswrod = driver.find_element_by_id('passwd')
userpasswrod.clear()
userpasswrod.click()
userpasswrod.send_keys('aaa888')
'''提交登陆'''
landing = driver.find_element_by_class_name('za_button')
landing.click()
'''获取当前信用额'''
iframe1 = driver.find_element_by_id('header')
driver.switch_to.frame(iframe1)
credit = driver.find_element_by_xpath('//*[@id="credit"]')
# print(driver.title)
# print(credit.get_attribute('text'))
# print(credit.title)
print('当前信用额度是{}'.format(credit.text))
'''获取球队名'''
team = driver.find_element_by_id('body')
driver.switch_to.frame(team)
# team1 = driver.find_element_by_class_name('team_name none')
team1 = driver.find_element_by_xpath('//*[@id="TR_11-1040166_1"]')
print(team1.text)
折腾了大半天 没效果
但是我把代码:
获取球队名 的代码跟 获取信用额度的代码 调换了下 可以执行球队名 但不执行 获取信用额度
如图:
![图片描述][4]
迷茫2017-04-18 09:56:36
(It took me two nights of self-study to understand this question)
It can be successful no matter who is put in front, because nested frames/iframes need to jump layer by layer, and can only jump from the defaultcontent to the highest frame, and the father frame jumps to the son frame. You can’t jump if you’re level
So you have to return to SI2_mem_index for the second time before jumping again (the two iframes of header and body are equal)
driver.switch_to_default_content()
driver.switch_to.frame('SI2_mem_index')
The test result picture cannot be inserted, so I put it on the blog: https://lypro09539.github.io/