代码:

#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. ionic4 可能忽略的一些细节

    1.iOS中,页面被状态栏遮挡的问题 有的说 具体是解决是  在config.xml   配置如下代码 <preference name="StatusBarStyle"   ...

  2. Sublime Text3高效开发之编写代码块(snippet)

    看到别人使用HBuilder X可以插入代码块,就想sublime text3有没有类似的功能呢,诶还真有.在sublime text3叫作snippet. -snippet是干什么的?:可以在你编写 ...

  3. drf从入门到飞升仙界 08

    断点调试使用 # 程序在debug模式运行,可以在任意位置停下,查看当前情况下变量数据的变化情况 # 使用pycharm调试程序 - 1.以debug模式运行. - 2.在代码左侧加入断点(红圈) - ...

  4. linux安装grafana成功后,登录成功,几天后无法访问

    页面提示: 解决方法: 扩展磁盘空间 检查浏览器版本:升级浏览器版本

  5. vue 清空element表单数据

    resetFields是用于针对整个表单的 Form Methods(整个表单) resetField 是针对表单项的 Form-Item Methods(表单的某一个项) this.$refs['e ...

  6. Win10中找回曾复制过的东西

    按Win+V,如果弹出的"剪贴板历史"设置已经打开,那么就可以找回.建议大家打开这项设置以防万一.

  7. js - 数字转中文

    js - 数字转中文 JavaScript 中将阿拉伯数字转换为中文 转换代码 var _change = { ary0: ['零', '一', '二', '三', '四', '五', '六', '七 ...

  8. 将bat文件设置为开机启动

    设置该bat文件开机自启动 1.右键计算机–>管理,选择系统工具–>计划任务程序: 2.选择创建任务,在弹出窗口中,输入任务名称,并选择不管用户是否登录都要运行–>使用最高权限运行: ...

  9. 关于JWT中RSA数据加密协议在.net中应用

    加密协议有哪些 加密协议分为对称加密和非对称加密. 对称加密就是将信息使用一个密钥进行加密,解密时使用同样的密钥,同样的算法进行解密. 非对称加密,又称公开密钥加密,是加密和解密使用不同密钥的算法,广 ...

  10. Java-集合概要

    集合概要 Java集合类存放于 java.util 包中,是一个用来存放对象的容器. 集合的两个主要接口是 Collection接口 和 Map 接口. 图片来源:菜鸟教程 集合的优点 区别 集合 数 ...