代码:

#coding = utf-8
from selenium import webdriver
import time
##############5-6:实现多窗口切换_start##############
driver = webdriver.Chrome()
driver.get('https://www.imooc.com/user/newlogin')
driver.find_element_by_name('email').send_keys('gj10010@163.com')
driver.find_element_by_name('password').send_keys('20200319gj')
driver.find_elements_by_class_name('moco-btn').click()
driver.get('https://www.imooc.com/user/setbindsns')
driver.find_elements_by_class_name('inner-i-box').find_elements_by_class_name('moco-btn-normal').click()
time.sleep(2)
current_handl = driver.current_window_handle
handl_list = driver.window_handles
print(handl_list)
for i in handl_list:
    if i != current_handl:
        time.sleep(2)
        driver.switch_to_window(i)
        driver.find_element_by_name('username').send_keys('13501913831')
        driver.find_element_by_name('password').send_keys('1351913831gj')
driver.close()
##############5-6:实现多窗口切换_end################
 
结果:
DevTools listening on ws://127.0.0.1:57048/devtools/browser/2f83b3cd-583f-4513-bccd-42c34432e0d4
Traceback (most recent call last):
  File "e:/30.Study/30.自动化测试/99.零基础入门 Python Web 自动化测试/10.seleniumCodePractice/202006/open_window_5-6.py", line 10, in <module>
    driver.find_elements_by_class_name('moco-btn').click()
AttributeError: 'list' object has no attribute 'click'
PS E:\30.Study\30.自动化测试\99.零基础入门 Python Web 自动化测试\10.seleniumCodePractice\202006>
 

原因分析:

 
对策:
driver.find_elements_by_class_name('moco-btn').click()
==>
driver.find_elements_by_class_name('moco-btn')[0].click()
 
 
 
 
 
 
 

5-6:实现多窗口之异常(AttributeError: 'list' object has no attribute 'click')的更多相关文章

  1. py+selenium 明明定位不到元素,但却不报错或是报错AttributeError: 'list' object has no attribute 'click'【已解决】

    问题:定位不到元素,但却不报错或者出现报错AttributeError: 'list' object has no attribute 'click' 如图  或者  解决方法:   将”driver ...

  2. Django 运行报异常:AttributeError: 'str' object has no attribute 'get'

    Technorati Tags: Python,Django,Web 在使用django.contrib.auth用户机制进行用户的验证.登录.注销操作时,遇到这个异常. 首先是写了一个登录的视图,要 ...

  3. PyQt: “AttributeError: 'Form' object has no attribute 'exec_'” when opening second window

    # -*- coding: utf-8 -*- import sys from PyQt5.QtWidgets import QApplication , QMainWindow from PyQt5 ...

  4. PyQt程序执行时报错:AttributeError: 'winTest' object has no attribute 'setCentralWidget'的解决方法

    用QtDesigner设计了一个UI界面,保存在文件Ui_wintest.ui中,界面中使用了MainWindow窗口,窗口名字也叫MainWindow,用PyUIC将其转换成了 Ui_wintest ...

  5. Django项目启动 AttributeError: ‘str‘ object has no attribute ‘decode‘ 问题

    Watching for file changes with StatReloader Performing system checks... System check identified no i ...

  6. Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

    最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...

  7. AttributeError: 'list' object has no attribute 'write_pdf'

    我在可视化决策树,运行以下代码时报错:AttributeError: 'list' object has no attribute 'write_pdf' 我使用的是python3.4 from sk ...

  8. attributeError:'module' object has no attribute ** 解决办法

    写了一个小脚本,执行的时候报错: Traceback (most recent call last): File "F:/test/qrcode.py", line 109, in ...

  9. AttributeError: 'module' object has no attribute 'TornadoAsyncNotifier'

    /*************************************************************************** * AttributeError: 'modu ...

  10. AttributeError: 'dict_values' object has no attribute 'translate'

    /***************************************************************************************** * Attribu ...

随机推荐

  1. Python elasticsearch_dsl 报错及解决方法

    Exception:maxClauseCount is set to 1024 原因:报错原因是Search限制一个bool查询中最多只能有1024个值或子查询,当超过1024时,会抛出异常. 解决办 ...

  2. ConvFormer: Closing the Gap Between CNN and Vision Transformers概述

    0.前言 相关资料: arxiv github 论文解读 论文基本信息: 发表时间:arxiv2022(2022.9.16) 1.针对的问题 CNN虽然效率更高,能够建模局部关系,易于训练,收敛速度快 ...

  3. redis运维与管理

    redis内存存储,速度极快 丰富的附件功能 1.持久化功能:降存储在内存的数据保存到硬盘 2.发布与订阅:将消息同时分发给多个客户端 3.过期键功能:为键设置一个过期时间,让它在指定的时间之后自动被 ...

  4. element-ui下表格头部字段hover显示tips信息

    记录一下表格头部加hover之后显示tips信息循环,或单独的el-table-column都可以哦 <el-table-column             prop="name&q ...

  5. [UnityShader]unity中2D Sprite显示阴影和接受阴影

    首先是效果 要让2D显示阴影,首先假设知道Unity阴影来源(shader中的ShadowCaster) 最简单的方法是,首先从官网下载Sprite-Default.Shader,查看源码 然后复制粘 ...

  6. vue页面添加锚点后 点击不改变URL

    html: <a @click="changeHash('#row')"> {{ $t("msg.desc1") }} </a>   j ...

  7. jreg视频内容整理

    目录 5种变得开心的方法 我(曾经)想死 别再问我过得好不好了 5种变得开心的方法 浪费时间,比如打游戏,什么都不干 停止思考,什么都不要想,刷视频 独处,不要跟别人分享你的痛苦,把自己的痛苦当作世界 ...

  8. Lua中创建新的文件夹

    如下: os.execute('mkdir 文件夹名称')

  9. Linux网络第六章:PXE高效批量网络装机及kickstart无人值守安装

    目录 一.PXE基础知识 二.PXE使用服务 三.高效批量网络装机实操 1.环境准备 2.配置dhcpd服务 3.配置FTP服务 4.配置TFTP服务 5.配置kickstart无人值守 6.启动服务 ...

  10. vue+vant打包,vue+vant-ui小程序,微信支付

    微信JS支付代码_前端调用微信支付接口 其实参照官方文档一步一步操作不是很难,但很多人在签名这个地方就总是出现问题,因为文档中签名时使用的字段大小写时错误的....好坑啊!!然而PHP版本的代码官方有 ...