代码:

#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. CLIP 改进工作串讲(下)学习笔记

    1.图像生成 1.1CLIPasso(semantically-aware object sketching) 将物体的照片变成简笔画的形式,希望即使有最少的线条,也能识别出来物体. 问题定义,在纸上 ...

  2. killall: command not found

    centos7精简安装后,使用中发现没有killall命令.经查找,可以通过以下命令解决:yum install psmisc -y 简单介绍一下 psmisc :Psmisc软件包包含三个帮助管理/ ...

  3. python requests库从接口get数据报错Max retries exceeded with url解决方式记录

    问题: session = HTMLSession() r: requests_html.HTMLResponse r = session.get(url=req["url"], ...

  4. mysql数据库查看版本号

    1.在命令行登录mysql,即可看到mysql的版本号 [root@mysql02 bin]# ./mysql -uroot -pEnter password: Welcome to the MySQ ...

  5. vite 运行或打包出现内存溢出的解决方案

    在使用vite运行或打包时出现了内存耗尽的报错 vite VUE npm run build 报错 npm ERR! code ELIFECYCLE npm ERR! errno 134 内存溢出 n ...

  6. 自定义Ribbon负载均衡

    需要在基包的上一级定义,不然会被扫到如:com.cn.me,要和me同级 然后自定义两个类 DshzsRandomRule类写自己定义的算法,DshzsRule写注入的bean import com. ...

  7. Spring的AOP源码解析(一)

    Spring AOP 使用介绍,从前世到今生 前面写过 Spring IOC 的源码分析,很多读者希望可以出一个 Spring AOP 的源码分析,不过 Spring AOP 的源码还是比较多的,写出 ...

  8. redis底层数据结构之双向链表(linkedlist)

    双向链表(linkedlist) redis的双向链表(linkedlist)是基于链表的一种数据结构 链表是一种常见的基础数据结构,是一种非顺序存储数据的线性表,在每一个节点里存储了下一个节点的指针 ...

  9. 基于 geojson数据类型面转线Transforms Polygons and MultiPolygons to LineStrings.

    function flatten(array) { return [].concat.apply([], array); } function polygonToLineString(coordina ...

  10. C++ CLI string

    String^ to std::string ` include <msclr\marshal_cppstd.h> marshal_as(String^) `