• 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)
    强制休眠十秒,有一定机会成功!
    每天进步一点点!
  • 相关阅读:
    链表的相关算法及应用(二)
    Hexo博客同时托管到github和coding
    Valine评论出现Code 403:访问被API域名白名单拒绝,请检查你的安全域名设置
    记一次Python爬虫入门
    基于SSM的个人博客
    JSTL和EL表达式遍历List数组
    bootstrap快速开发响应式页面
    标签随机文字颜色和字体大小的实现方法
    安卓Service和Broadcast实现简单的音乐播放器
    ListView设置OnItemClickListener点击没有反应
  • 原文地址:https://www.cnblogs.com/qianjunjun/p/13390764.html
Copyright © 2020-2023  润新知