在python + selenium 中经常会遇到找到的元素不唯一,导致定位到的元素不是预期的或者定位不到元素

解决方法:只要在页面进行确认找到的元素唯一后,再进行操作

页面确认方法:

 1、通过html中检索功能确认

  进入开发者模式:点击右上角三个点-->选则 search 进行查找

      或者直接ctrl + F (windows下)/ command + F (mac系统下)

  

  

  如下图进行查找,查找方法和 selenium 中一样,如 class = ‘mnav’则查找中输入 .mnav; id = ‘username’ 则输入#username; name = ‘pwd’则输入name=‘pwd’等

  查找出后可在检索框后面确定找到的数量,然后通过上下键进行切换观察是否在html中唯一

  这种方法有点麻烦,但也是确认元素唯一的一种方法,不推荐使用  

  

 2、通过控制台(Console)确认

  复制要查找的元素,例如:查找class = ‘.mnav’,则在控制台中输入 document.getElementsByClassName('mnav')

  如下图也可以确认元素是否唯一

  控制台中确认,和 selenium 定位类似 

  document.getElementById()        // find id

  document.getElementsByClassName()   // find classname 

  document.getElementsByName()        // find name

  document.getElementsByTagName()   // find tag 

   

  

  

selenium-确定找到的element唯一(三)的更多相关文章

  1. Selenium Web 自动化 - 项目实战(三)

    Selenium Web 自动化 - 项目实战(三) 2016-08-10 目录 1 关键字驱动概述2 框架更改总览3 框架更改详解  3.1 解析新增页面目录  3.2 解析新增测试用例目录  3. ...

  2. 【转】Selenium 报错:Element is not clickable at point的解决办法

    天一同学在写Selenium Java脚本时遇到一个问题,登录进入系统之后,要点击左侧的一个菜单,但是执行到该语句时报下面的错误: Firefox中报错如下:org.openqa.selenium.E ...

  3. org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element

    org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element(识别不到想要的元素) 想获取 ...

  4. UI自动化(selenium+python)之元素定位的三种等待方式

    前言 在UI自动化过程中,常遇到元素未找到,代码报错的情况.这种情况下,需要用等待wait. 在selenium中可以用到三种等待方式即sleep,implicitly_wait,WebDriverW ...

  5. selenium webdriver API详解(三)

    本系列主要讲解webdriver常用的API使用方法(注意:使用前请确认环境是否安装成功,浏览器驱动是否与谷歌浏览器版本对应) 一:获取页面元素的文本内容:text 例:获取我的博客名字文本内容 代码 ...

  6. Python+Selenium之cannot focus element 解决方法

    有时候刚进入页面输入第一个值时脚本会报错:cannot focus element 贴下我的脚本和解决办法供大家参考 我原本的脚本是: WebDriverWait(driver,15,0.5).unt ...

  7. java使用Selenium操作谷歌浏览器学习笔记(三)键盘操作

    我们用Selenium打开网页后,可能需要在输入框输入一些内容等等,这时候就需要键盘操作了 使用sendKEys进行键盘操作,在bing的搜索框中输入内容并点击跳转 1 import org.open ...

  8. fix org.openqa.selenium.NoSuchWindowException when find element on windows8.1 ie11.

    Steps:1.I was able to resolve the issue after adding the site URL under trusted sites of IE. The sam ...

  9. Selenium 入门到精通系列:三

    Selenium 入门到精通系列 PS:Driver_Element 常用方法 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2 ...

随机推荐

  1. [Swift]LeetCode887. 鸡蛋掉落 | Super Egg Drop

    You are given K eggs, and you have access to a building with N floors from 1 to N. Each egg is ident ...

  2. Python内置函数(19)——eval

    英文文档: eval(expression, globals=None, locals=None) The arguments are a string and optional globals an ...

  3. vue + hbuilder 开发备忘录

    踩过的坑: axios 安卓低版本兼容性处理 阻止表单中,button默认事件,出现刷新问题. 设置滚动条的位置 vue 数据和对象数据变化 dom结构不变 android低版本 白屏问题 你是不是用 ...

  4. Carousel轮播图

     <div id="carousel-example-generic" class="carousel slide" data-ride="ca ...

  5. [Leetcode]695. Max Area of Island

    Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...

  6. shell实战之Linux主机系统监控

    1.系统监控概述 采集的监控信息主要有内存占用率,CPU占用率,当前在线用户,磁盘挂载及磁盘空间使用率,平均每秒写入流量,平均每秒流出流量.磁盘IO:平均每秒从磁盘读入内存的速率,平均每秒从内存写入磁 ...

  7. Chapter 5 Blood Type——11

    "I just wondered… if you could warn me beforehand the next time you decide to ignore me for my ...

  8. OAuth2.0 原理简介

    写在前面: 在正式介绍OAuth2.0之前我们先来看一个场景:小李是一个文艺小青年, 经常喜欢出去旅游并且把自己旅行中的美景照片分享到各大社交网站上,比如朋友圈,新浪微博.小李马上要向女朋友求婚了,他 ...

  9. 【ASP.NET Core快速入门】(十二)JWT 设计解析及定制

    前言 上一节我们讲述的书如何使用jwt token,而且上一节的token是要加Authorization:bearer XXXXXXXXXXXX才能访问. 这一节我们来研究如何自定义类似jwt的to ...

  10. MySQL 索引及查询优化总结

    本文由云+社区发表 文章<MySQL查询分析>讲述了使用MySQL慢查询和explain命令来定位mysql性能瓶颈的方法,定位出性能瓶颈的sql语句后,则需要对低效的sql语句进行优化. ...