Selenium - 如何捕获页面上的所有网页元素和关联的定位器? [英] Selenium - How to capture all web page elements and associated locators on a page?

查看:829
本文介绍了Selenium - 如何捕获页面上的所有网页元素和关联的定位器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用哪些Java / Selenium命令来捕获/获取/输出单个网页的所有元素和关联元素定位器? Selenium IDE允许您一次检查一个元素。如果您有数千个要自动化的元素,那就是一个问题。是否有工具或Java / selenium命令可以用来立即获取我网页上的所有对象/元素,然后可以自定义输出以满足我的需求?
如果你有使用SilkTest的经验,我想要类似于在SilkTest中生成Window声明的东西。 SilkTest的记录窗口声明工具捕获页面上所有对象/元素的标记/属性/定位器信息,并允许您将代码粘贴到库或包含文件。因此,通过一次或两次单击,我可以捕获并定义SilkTest中的许多对象。是否有工具或命令为Selenium做类似的事情?我正在使用Java,因此我喜欢Java中的任何示例。谢谢。

What Java/Selenium commands can I use to capture/get/output for all elements and associated element locators for a single webpage? The Selenium IDE allows you to inspect one element at a time. That is a problem if you have thousands of elements to automate. Is there a tool or Java/selenium command that I can use to get all of the objects/elements on my web page at once and then maybe customize the output to suite my needs? If you have any experience with SilkTest, I'd like something analogous to generating Window Declarations in SilkTest. SilkTest's Record Window Declaration tool captures tag/property/locator information for all of the objects/elements on a page and allows you to paste the code to your library or include file. So with one or two clicks I can capture and define dozens of objects in SilkTest. Is there a tool or command that does something similar for Selenium? I'm using Java so I'd like any examples in Java. Thanks.

推荐答案

使用findElementsByXPath并指定所有元素为我工作。例如

Using findElementsByXPath and specifying 'All elements' worked for me. E.g.

findElementsByXPath("//*")

http://www.w3schools.com/ xml / xpath_syntax.asp

这篇关于Selenium - 如何捕获页面上的所有网页元素和关联的定位器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆