代码:

#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. 2373. 矩阵中的局部最大值 (Easy)

    问题描述 2373. 矩阵中的局部最大值 (Easy) 给你一个大小为 n x n 的整数矩阵 grid . 生成一个大小为 (n - 2) x (n - 2) 的整数矩阵 maxLocal ,并满足 ...

  2. ucloud 签名算法

    # Python version:3.6.5 import hashlib import urllib from urllib.parse import urlparse params = { &qu ...

  3. Anaconda jupyter notebook 出现 kernel error 解决办法

    kenel出现错误如图: 解决办法 首先打开Anaconda Prompt输入jupyter kernelspec list查看安装的内核和位置进入安装目录,打开kernel.jason, 查看pyt ...

  4. HttpClient Post 提交表单数据

    运行环境 .net 4.6.1 //为防止因HTTPS证书认证失败造成API调用失败,需要先忽略证书信任问题 var sslHandler = new HttpClientHandler() { }; ...

  5. LP1-5:常见BUG

    一般常见的错误放在通用的代码里.错误判断就是if/else,太多影响性能,接口只需要加入必要的判断就好.

  6. swagger TypeError: Failed to fetch

    最近开发一个项目,项目接口规范是swagger,初次使用swagger遇见很多问题,通过写博记录在项目中遇见的swagger各种情况 我项目中解决方法: 改为: 需要与自己在laravel  框架中e ...

  7. Mac用自带软件QuickTime Player进行录屏

    ​ Mac电脑用自带软件QuickTime Player进行录屏的教程,几步就可以学会,挺简单的. 1.首先,找到并打开QuickTime Player软件.可以鼠标右键这个图标,选择"选项 ...

  8. Mac 用Parallels Desktop安装Windows 10

    下面就一步一步来学习如何用Parallels Desktop安装Windows 10系统: 1.首先下载并安装  Parallels Desktop 14版,下载 Windows 10 系统镜像 2. ...

  9. Mysql主从备份指定库别名

    问题:replicate-rewrite-db  不生效 解决方案: 尝试 注释掉 replicate-do-db ,不写 replicate-ignore-db,只写 replicate-rewri ...

  10. Oracle常用的日期操作函数 to_char()和to_date

    https://www.cnblogs.com/zhangliang88/p/12924407.html