最好的方法来检测java中的seleniumRC网页上的元素 [英] best way to detect an element on a web page for seleniumRC in java

查看:114
本文介绍了最好的方法来检测java中的seleniumRC网页上的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 SeleniumRC 检测网页上的元素进行自动测试的最佳方法是什么?使用Java?我知道有XPath元素和CSS元素,但哪一个是最好的?

What is the best way to detect an element on a webpage for automated testing using SeleniumRC using Java?. I know that there are XPath elements and CSS elements, but which one is best?

谢谢!
Nitin

thanks! Nitin

推荐答案

在我看来,最准确的方法是XPath,你可以使用XPath来描述确切的位置

In my opinion, the most accurate way is XPath as you can use XPath's to describe the exact position of an element within the DOM, however there are some instances where CSS locators work better than XPaths.

使用selenium的ID定位器是最简单的,但除非你的元素

Using selenium's ID locator is the most simple, but unless the element you are looking for has an ID not always useful.

使用XPath时最大的负面影响是Selenium RC和带有不良JavaScript渲染引擎的浏览器的性能(Think IE6 / IE7)。相当多的工作已经穹顶,尝试和纠正这,所以如果你使用良好形成的XPath的,只搜索DOM的特定部分,这个问题应该是最小的。 Selenium webdriver的实现速度要快得多。

The biggest negative when using XPath's is the performance with Selenium RC and browsers with bad JavaScript rendering engines (Think IE6/IE7). Quite a bit of work has been dome to try and rectify this so if you use well formed XPath's that only search specific parts of the DOM this problem should be minimal. The Selenium webdriver implementation is much faster.

总结是没有一个答案,它取决于你想要的定位器,以及你正在测试哪些浏览器。我个人在99%的实例中使用XPath。

The summary is really there is no one answer it depends what you want out of a locator, and which browsers you are testing. I personally use XPath in 99% of instances.

我个人使用XPath几乎只使用偶尔的CSS定位器。

I personally use XPath almost exclusively with the occasional CSS locator.

这篇关于最好的方法来检测java中的seleniumRC网页上的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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