代码:

#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. Codeforces Round #748 (Div. 3) - D2. Half of Same

    数论 + 随机化 [Problem - D2 - Codeforces](https://codeforces.com/contest/1749/problem/D) 题意 给定一个长度为 \(n\; ...

  2. 数值分析之解线性方程组的直接方法 5.X

    矩阵 谱分解 设 \(\boldsymbol{A}=a_{i j} \in \mathbb{R}^{n \times n}\) , 若存在数 \(\lambda\) (实数或复数) 和非零向量 \(\ ...

  3. Linux与Windows对比

    1. 前言 Windows是微软为个人台式机/设备或电脑(PC)开发的一系列操作系统.计算机操作系统(OS).每个操作系统都有一个图形用户界面(GUI),桌面允许用户查看所有文件.视频等.Window ...

  4. python 链接云端数据库/远程数据库 可以使用原始Odbc

    class MySqlOdbc: def __init__(self): self.sqlhead = None # 当前数据链接句柄 self.mycursor = None # 当前游标 &quo ...

  5. 使用shell判断文件夹中是否包含文件

    #!/bin/bash directory="/path/to/directory" if [ $(ls -A $directory) ]; then echo "有文件 ...

  6. calendar.getActualMaximum(calendar.DAY_OF_MONTH)的陷阱,2月份最后一天成了3月3号

    引用一下别人的链接: https://blog.csdn.net/dongyuxu342719/article/details/78131697

  7. 【SSO单点系列】(6):CAS4.0 之中文乱码

    CAS登录会将登录名回传给客户端以xml的格式   但是回传后乱码客户端无法正确解析 二.解决方法 ServiceValidateController.java private ModelAndVie ...

  8. BT做种

    BT方式:BT方式属于P2P传输,客户机之间可互传数据,大大提高传输效率,推荐使用.此处以qBittorrent做种为示例,主要有以下几个要点1.启用内置Tracker(或用其他同类软件代替)2.启用 ...

  9. errgroup.Group

    在一组 Goroutine 中提供了同步.错误传播以及上下文取消的功能,我们可以使用如下所示的方式并行获取网页的数据: package main import ( "fmt" &q ...

  10. Gitbook编写JSON文件

    title: Gitbook编写JSON文件 # 标题 date: 2020-10-31 16:34:30 updated: 2020-12-31 categories: 前端 tags: JSON ...