//通过id
WebElement element = driver.findElement(By.id("coolestWidgetEvah"));
//通过className
List<WebElement> cheeses = driver.findElements(By.className("cheese"));
//通过tagName
WebElement frame = driver.findElement(By.tagName("iframe"));
//通过name
WebElement cheese = driver.findElement(By.name("cheese"));
//通过linkText
<a href="http://www.google.com/search?q=cheese">cheese</a>
WebElement cheese = driver.findElement(By.linkText("cheese"));
//通过部分linkText
<a href="http://www.google.com/search?q=cheese">search for cheese</a>
WebElement cheese = driver.findElement(By.partialLinkText("cheese"));
//通过css
<div id="food"><span class="dairy">milk</span><span class="dairy aged">cheese</span></div>
WebElement cheese = driver.findElement(By.cssSelector("#food span.dairy.aged"));//通过xpath,比较麻烦//通过javaScript
WebElement element = (WebElement) ((JavascriptExecutor)driver).executeScript("return $('.cheese')[0]");
List<WebElement> labels = driver.findElements(By.tagName("label")); List<WebElement> inputs = (List<WebElement>) ((JavascriptExecutor)driver).executeScript( "var labels = arguments[0], inputs = []; for (var i=0; i < labels.length; i++){" + "inputs.push(document.getElementById(labels[i].getAttribute('for'))); } return inputs;", labels);

转载于:https://www.cnblogs.com/jtestroad/p/7088583.html

selenium常用获取元素点相关推荐

  1. selenium 常用操作

    官方文档: https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webdriver.WebDriver. ...

  2. Selenium Web 自动化 - Selenium常用API

    Selenium Web 自动化 - Selenium常用API 2016-08-01 目录 1 对浏览器操作   1.1 用webdriver打开一个浏览器   1.2 最大化浏览器&关闭浏 ...

  3. java request获取url_java中HttpServletRequest常用获取url、资源名等方法总结

    HttpServletRequest客户端获取请求,客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中.所以我们能够从对象中获取相应信息 端口 request.getSe ...

  4. php jquery点击事件,jQuery操作html元素点击事件详解

    这次给大家带来jQuery操作html元素点击事件详解,jQuery操作html元素点击事件的注意事项有哪些,下面就是实战案例,一起来看一下. 移除或禁用html元素的点击事件可以通过css实现也可以 ...

  5. python爬取下拉列表数据_Python+selenium之获取文本值和下拉框选择数据

    Python+selenium之获取文本值和下拉框选择数据 一.结合实例进行描述 1. 实例如下所示: #新增标签操作 def func_labels(self): self.driver.find_ ...

  6. python selenium爬虫代码示例_python3通过selenium爬虫获取到dj商品的实例代码

    先给大家介绍下python3 selenium使用 其实这个就相当于模拟人的点击事件来连续的访问浏览器.如果你玩过王者荣耀的话在2016年一月份的版本里面就有一个bug. 安卓手机下载一个按键精灵就可 ...

  7. vue中父元素点击事件与子元素点击事件冲突

    vue中父元素点击事件与子元素点击事件冲突 在做vue项目的时候,遇到子元素有点击事件,父元素也有点击事件,当点击子元素时往往触发的是父元素的点击事件,产生冲突,怎样解决这个问题呢?这就用到vue事件 ...

  8. selenium常用命令之操作页面元素及获取元素内容的事件整理

    /**id <input type="text" id="phone" name="phone" class="LoginT ...

  9. java selenium常用API(WebElement、iFrame、select、alert、浏览器窗口、事件、js) 一

     WebElement相关方法 1.点击操作 WebElement button = driver.findElement(By.id("login")); button.clic ...

最新文章

  1. nanomsg:ZeroMQ作者用C语言新写的消息队列库
  2. Python多版本共存之pyenv
  3. Nodejs学习笔记(五)--- Express安装入门与模版引擎ejs
  4. 【白话机器学习】算法理论+实战之支持向量机(SVM)
  5. apache camel_Apache Camel –从头开始开发应用程序(第2部分/第2部分)
  6. MySQL服务器意外关机-无法启动多实例
  7. 元素可视区client系列(附实例)
  8. 【UVA12304】2D Geometry 110 in 1!(外接圆/内切圆/切点等圆相关问题的模版题)
  9. 用gambit学博弈论--完全信息动态博弈(一)
  10. 【Gym 100015B】Ball Painting(DP染色)
  11. Outlook打不开的问题
  12. java 打开url连接访问不了,android 应用Java自带的HttpURLConnection 连接网络 读取返回数据...
  13. 【jmx学习】2、jmx之Html Adaptor
  14. 网站推行:外链建设需求留意什么?
  15. python可视化的图表汉字显示成框框_数据可视化——Matplotlib输出中文显示问题...
  16. LUA———Lua和C 区别
  17. 高端大气上档次的fullPage.js
  18. 从零开始之驱动发开、linux驱动(四十五、DM9000网卡驱动)
  19. 如何在BPA600添加新的协议
  20. Yslow安装使用, 网站性能工具Yslow

热门文章

  1. win10系统下安装Linux虚拟机以及在虚拟机上安装Ubuntu
  2. 【Foreign】朗格拉日计数 [暴力]
  3. annotation-driven里面的argument-resolvers参数??
  4. java 环境 搭建
  5. Linux 块与文件大小
  6. 对TRIM SCSI命令的一些分析
  7. java 异步查询转同步多种实现方式:循环等待,CountDownLatch,Spring EventListener,超时处理和空循环性能优化...
  8. jQuery-ui源代码重点难点分析
  9. 世界杯来了!小程序赛事操作来一波~
  10. SpringMVC-高级参数绑定