zoukankan      html  css  js  c++  java
  • selenium.common.exceptions.WebDriverException: Message: TypeError: rect is undefined

    今天写python测试脚本遇到这个问题,问题出现的背景是:登录需要操作滑动条,图片吻合后才验证通过。系统是固定十张图片,随机产生;当验证通过后一直报错selenium.common.exceptions.WebDriverException: Message: TypeError: rect is undefined

    贴上代码,因为啥帮其他朋友测试,代码比较简易,没时间整理,将就一下;如果有朋友知道解决办法,麻烦留言下,不胜感激!

    from selenium import webdriver
    from selenium.webdriver import ActionChains
    import time
    from selenium.common.exceptions import NoSuchElementException
    def is_element_present(driver, how, what):
        try:
            driver.find_element(by=how, value=what)
        except NoSuchElementException:
            return False
        return True
    driver = webdriver.Firefox()
    driver.get('https://www.duoduodaizhang.com/login')
    time.sleep(2)
    phone = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[1]/div/div[2]/div[2]/div/div[1]/input")
    phone.click()
    phone.send_keys('1897XXXXXXXX')
    password  = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[1]/div/div[2]/div[2]/div/div[2]/input")
    password.click()
    password.send_keys('XXXXXXX')
    button = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[1]/div/div[2]/div[2]/div/div[3]/button")
    button.click()
    time.sleep(2)
    huadong = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[1]/div[2]/div[3]/div/div/div[2]/div/div[2]/div")
    action_chains = ActionChains(driver)
    for i in range(0,10):
        action_chains.drag_and_drop_by_offset(huadong,200,0).perform()
        if is_element_present(driver,'xpath',"/html/body/div[1]/div/div/div[1]/div/div[1]/ul/li[5]/a[2]")==False:
            continue
        if is_element_present(driver, 'xpath', "/html/body/div[1]/div/div/div[1]/div/div[1]/ul/li[5]/a[2]") == True:
            print('success')
            break

     不稳定的解决办法:

    for i in range(0,10):
        action_chains.drag_and_drop_by_offset(huadong,200,0).perform()
    time.sleep(10)
    强制休眠十秒,有一定机会成功!
    每天进步一点点!
  • 相关阅读:
    第一次个人作业-热身
    OO总结
    oo第三单元总结
    oo第二单元总结
    软件工程 —— 课程回顾与个人总结
    BUAA软件案例分析——智能表单抽取识别
    软件工程—结对项目博客
    轨迹预测文献阅读整理(轨迹多样性、车辆轨迹、图神经网络、潜码)
    软件工程
    软件工程
  • 原文地址:https://www.cnblogs.com/qianjunjun/p/13390764.html
Copyright © 2011-2022 走看看