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)
    强制休眠十秒,有一定机会成功!
    每天进步一点点!
  • 相关阅读:
    linux嵌入式系统交叉开发环境
    Codeforces Round #208 E. Dima and Kicks
    mvn 编译错误java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter. <init>(Z)V
    黑马程序员_<<TCP>>
    微信/易信公共平台开发(四):公众号调试器 (仿真微信平台,提供PHP源码)
    用pdb调试OpenStack Havana
    MySql Odbc等驱动下载地址分享下
    导入exce表格中的数据l到数据库
    关闭数据备份信息写入数据库日志
    SQL Server之RAID简介
  • 原文地址:https://www.cnblogs.com/qianjunjun/p/13390764.html
Copyright © 2011-2022 走看看