qq_34040741 2017-09-17 15:45 采纳率: 100%
浏览 1643
已结题

selenium元素已显示点击却报错ElementNotInterac...

代码如下:
# 此类封装一些常用的浏览器操作
class BasePage(object):
def init(self,driver):
self.driver = driver

# 退出浏览器
        def quit_browser(self):
    self.driver.quit()

    # 显式等待_元素可见_XPATH
        def wait_explicit_located(self,x_path):
    try:
        WebDriverWait(self.driver, 5).until(
            EC.visibility_of_all_elements_located((By.XPATH, x_path)))
        logger.info(u"目标元素已显示 %s" %x_path)
    except TimeoutException as e:
        logger.error(u"元素%s显示异常 %s" % (x_path,e))
        print u'元素显示异常%s' %x_path
        self.get_windows_image()

#输入
        def type(self,selector,text):
    el = self.find_element(selector)
    el.clear()
    try:
        el.send_keys(text)
        logger.info("Had type \' %s \' in inputBox" % text)
    except NameError as e:
        logger.error("Failed to type in input box with %s" % e)
        self.get_windows_image()
    ......

from ZJCH_selenium.framework.base_page import BasePage

#此类是登录页面的方法
class LoginPage(BasePage):
loginname_box = "xpath=>.//*[@class='login']//*[@class='lg']"
pwd_box = "xpath=>.//*[@class='login']//*[@class='pwd']"
verification_box = "xpath=>.//*[@class='login']//*[@name='yanzheng']"
login_btn = "xpath=>.//*[@class='login']//*[@class='log log1']"
#5位验证码定位
yzm1 = "xpath=>.//*[@class='rt']/span[1]"
yzm2 = "xpath=>.//*[@class='rt']/span[2]"
yzm3 = "xpath=>.//*[@class='rt']/span[3]"
yzm4 = "xpath=>.//*[@class='rt']/span[4]"
yzm5 = "xpath=>.//*[@class='rt']/span[5]"
login_in = "xpath=>.//*[@class='alert_information']/b"  #我知道了按钮的定位

    def type_loginname(self, text):
    self.type(self.loginname_box, text)

def type_pwd(self, text):
    self.type(self.pwd_box, text)

    def get_yzm(self):
    yzm_1 = self.get_text(self.yzm1)
    yzm_2 = self.get_text(self.yzm2)
    yzm_3 = self.get_text(self.yzm3)
    yzm_4 = self.get_text(self.yzm4)
    yzm_5 = self.get_text(self.yzm5)
    yzm = yzm_1 + yzm_2 + yzm_3 + yzm_4 + yzm_5
    return yzm

 #输入验证码
def type_verification(self, text):
    self.type(self.verification_box, text)

 #点击登录按钮
def send_login_btn(self):
    self.click(self.login_btn)

#点击我知道了
def send_iknow_btn(self):
    self.click(self.login_in)

import unittest
from ZJCH_selenium.framework.browser_engine import BrowserEngine
from ZJCH_selenium.pageobjects.login_page import LoginPage

#此类是测试登录功能
class test_ZJCH_Login(unittest.TestCase):
def setUp(self):
    browse = BrowserEngine(self)
    self.driver = browse.open_browser(self)
def tearDown(self):
    self.driver.quit()
def test_login(self):
    loginpage = LoginPage(self.driver)
    loginpage.wait_explicit_located(".//*[@class='login']")
    loginpage.type_loginname('admin')      #输入用户名
    loginpage.type_pwd('123456')       #输入密码
    yzm = loginpage.get_yzm()       #得到验证码
    loginpage.type_verification('{}'.format(yzm))           #输入验证码
    loginpage.send_login_btn()                  #点击登录按钮
    loginpage.wait_explicit_located(".//*[@class='alert_information']/b")
    loginpage.send_iknow_btn()               #点击确认登录

图片说明

** 利用unittest执行测试用例,登录页面可以正常登录,点击我知道了按钮后也正常进入系统首页,从网页上看没有任何异常,但用HTMLTestRunner缺报错,如图**
图片说明

**我测试过多次,执行到loginpage.wait_explicit_located(".//*[@class='alert_information']/b"),都没有错误,执行loginpage.send_iknow_btn() 就报错(问题是网页操作正常,可以进入系统首页,但为什么生成的测试报告缺有报错),
我试了下把loginpage.send_iknow_btn()去掉,采用
self.driver.find_element_by_xpath(".//*[@class='alert_information']/b").click()
如果采用这句代码就正常运行没有任何报错,这是为什么呢?
[我知道了]这个窗口是在验证了用户登录成功后弹出的一个提示窗口,点击就可以进入系统首页的

另:我已经验证过,loginpage.wait_explicit_located(".//*[@class='alert_information']/b")这句显示等待已经成功的等待了【我知道了】窗口显示才执行的loginpage.send_iknow_btn()
到loginpage.wait_explicit_located(".//*[@class='alert_information']/b")都没有任何问题,元素已显示,点击操作也正常,但是生成到报告里就报错,哪位大神能帮我看看是为什么啊,真的想不通,我的HTMLTestRunner应该不会有问题的,其他测试用例都没什么问题**

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 关于#python#的问题:自动化测试