51Testing软件测试论坛

标题: selenium模拟登录163 [打印本页]

作者: 15889369825    时间: 2016-12-26 11:42
标题: selenium模拟登录163
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re

class test (unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(30)
        self.base_url = "http://test.robotscloud.com/"
        self.verificationErrors = []
        self.accept_next_alert = True

    def test_(self):
        driver = self.driver
        driver.get(self.base_url + "/#")
        driver.find_element_by_link_text(u"忘记密码").click()
        driver.find_element_by_id("submit-find-back").click()
        driver.find_element_by_id("email").clear()
        driver.find_element_by_id("email").send_keys("123456789@163")
        driver.find_element_by_id("submit-find-back").click()
        driver.find_element_by_id("email").clear()
        driver.find_element_by_id("email").send_keys("123456789@163.com")
        driver.find_element_by_id("submit-find-back").click()
        driver.find_element_by_id("authcode").clear()
        driver.find_element_by_id("authcode").send_keys("3333")
        driver.find_element_by_id("submit-find-back").click()
        driver.find_element_by_css_selector("img.captcha-img").click()
        driver.find_element_by_id("email").click()
        driver.find_element_by_id("email").clear()
        driver.find_element_by_id("email").send_keys("")
        driver.find_element_by_id("submit-find-back").click()
        driver.find_element_by_id("email").click()
        driver.find_element_by_id("email").clear()
        driver.find_element_by_id("email").send_keys("cylan_123@@163.com")
        driver.find_element_by_id("submit-find-back").click()
        driver.find_element_by_id("email").clear()
        driver.find_element_by_id("email").send_keys("cylan_123@163.com")
        driver.find_element_by_id("authcode").clear()
        driver.find_element_by_id("authcode").send_keys("333")
        driver.find_element_by_id("submit-find-back").click()
        driver.find_element_by_id("authcode").clear()
        driver.find_element_by_id("authcode").send_keys("")
        driver.find_element_by_id("submit-find-back").click()
        driver.find_element_by_id("authcode").clear()
        driver.find_element_by_id("authcode").send_keys("3333")
        driver.find_element_by_id("submit-find-back").click()
        driver.find_element_by_id("to-login-email").click()
        driver.find_element_by_id("email").clear()
        driver.find_element_by_id("email").send_keys("cylan_123@163.com")
        driver.find_element_by_id("authcode").clear()
        driver.find_element_by_id("authcode").send_keys("7616")
        driver.find_element_by_id("submit-find-back").click()
        driver.find_element_by_id("login-email").click()
        time.sleep(3)
        driver.switch_to_frame("x-URS-iframe")
        time.sleep(3)
        driver.find_element_by_name("email").clear()
        driver.find_element_by_name("email").send_keys("cylan_123")
        driver.find_element_by_name("password").clear()
        driver.find_element_by_name("password").send_keys("cylan123456")
        time.sleep(3)
        driver.find_element_by_id("dologin").click()
        time.sleep(3)
        driver.find_element_by_id("_mail_tree_1_68count").click()
        driver.find_element_by_css_selector("span.da0").click()
        driver.find_element_by_link_text(u"立即重置密码").click()

        怎么定位这个立即重置密码   不要定位链接                 driver.find_element_by_id("_mail_tree_1_68count").click()
        driver.find_element_by_css_selector("span.da0").click()这两句是不是我以后进来它定位的都是邮箱中的第一封邮件   还是指定的某个邮件   因为这个在页面上看不到页面元素  所以不知道是什么意思  能帮忙解答下么

作者: 掉渣饼    时间: 2016-12-26 16:12
I’m sorry,我之前告诉你了怎么进入iframe,忘记告诉你了怎么跳出iframe

driver.find_element_by_id("_mail_tree_1_68count").click()
前面加
driver.switch_to_default_content()


driver.find_element_by_link_text(u"立即重置密码").click()
前面加上
driver.switch_to_frame("1482739972761_frameBody")

原因就是如果你定位的元素父节点中在某个iframe下面,需要先进入这个iframe,如果后面定位的元素又不在这个iframe中,需要跳出来
PS:结合页面源码你看下
作者: 15889369825    时间: 2016-12-26 16:35
掉渣饼 发表于 2016-12-26 16:12
I’m sorry,我之前告诉你了怎么进入iframe,忘记告诉你了怎么跳出iframe

driver.find_element_by_id(" ...

好的,谢谢
作者: 15889369825    时间: 2016-12-26 16:41
15889369825 发表于 2016-12-26 16:35
好的,谢谢

有什么方法能指定打开最前面的邮件而不是指定的某个邮件
作者: 15889369825    时间: 2016-12-26 16:43
掉渣饼 发表于 2016-12-26 16:12
I’m sorry,我之前告诉你了怎么进入iframe,忘记告诉你了怎么跳出iframe

driver.find_element_by_id(" ...

有什么方法能指定打开最前面的邮件而不是指定的某个邮件,就是我发一封邮件  我这边就打开最新的
作者: 掉渣饼    时间: 2016-12-26 17:48
15889369825 发表于 2016-12-26 16:43
有什么方法能指定打开最前面的邮件而不是指定的某个邮件,就是我发一封邮件  我这边就打开最新的

可以用xpath定位方法
作者: 15889369825    时间: 2016-12-27 18:24
掉渣饼 发表于 2016-12-26 17:48
可以用xpath定位方法

E
======================================================================
ERROR: test_ (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "F:\萝卜头自动化脚本\企业平台\忘记密码.py", line 72, in test_
    driver.switch_to_frame("1482743505435_frameBody")
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 574, in switch_to_frame
    self._switch_to.frame(frame_reference)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\switch_to.py", line 84, in frame
    self._driver.execute(Command.SWITCH_TO_FRAME, {'id': frame_reference})
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
NoSuchFrameException: Message: no such frame
  (Session info: chrome=54.0.2840.99)
  (Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 6.1.7601 SP1 x86)


----------------------------------------------------------------------
Ran 1 test in 22.673s

FAILED (errors=1)
>>>

上面的报错了
作者: jingzizx    时间: 2017-1-25 13:28





欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2