Selenium Webdriver高亮元素,然后单击 [英] Selenium webdriver highlight element before clicking

查看:336
本文介绍了Selenium Webdriver高亮元素,然后单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一组用Python编写的硒UI测试.在以前的项目中,我使用的是WatiN和C#.

I'm working on a set of selenium UI tests that are written in Python. On a previous project I was using WatiN and C#.

您可以启用WatiN框架的功能,以突出显示"您单击,选择或键入的元素.在执行操作时,该元素周围会出现黄色边框.我发现这在对损坏的测试进行故障排除时非常有用,通常可以从测试运行中查看是否单击了错误的元素.

The WatiN framework had a feature you could enable that would 'highlight' the element you were clicking, selecting or typing into. The element would get a yellow border around it while the action was performed. I found this extremely helpful while troubleshooting broken tests, I could often see from the test run if the wrong element was being clicked.

我想知道Selenium Webdriver是否具有可以打开的类似功能.基本上,我想以某种视觉方式指示正在与哪些元素进行交互.

I was wondering if Selenium webdriver has a similar feature that I can turn on. Basically I would like some sort of visual indication of what element is being interacted with.

谢谢!

推荐答案

Selenium RC可以做到这一点,但是WebDriver中没有直接的API方法可以做到这一点.您的选择是:

Selenium RC could do this but there is no direct API method to do this in WebDriver. Your options are:

1)在您的语言绑定中使用WebDriverBackedSelenium实现来访问Highlight方法.

1) Use the WebDriverBackedSelenium implementation in your language bindings to access the Highlight method.

2)只需使用JavascriptExecutor(或您的语言绑定中的类似实现)调用一些javascript,即可为您完成工作.这将模仿 Selenium RC/option 1 (硒RC/选项1)将实现的效果.

2) Simply call some javascript using the JavascriptExecutor (or similar implementation in your language bindings) to do the job for you. This will mimic what Selenium RC/option 1 would achieve.

要调用的Javascript存在于此处:

The Javascript to call exists here:

http://code. google.com/p/selenium/source/browse/javascript/selenium-core/scripts/htmlutils.js

要注意的功能是highlight功能.只需使用JavascriptExecutor加载此脚本(搜索以使用您的编程语言进行搜索即可).

The function to note is the highlight function. Just load this script using the JavascriptExecutor (search to find out how to do this in your programming language).

然后可以对此进行比较,以查看Java API中的WebDriverBackedSelenium实现如何使用它:

You can then compare this to see how the WebDriverBackedSelenium implementation in the Java API's are using it:

使用此代码,以自己的代码执行此操作.

Use this, to do this same in your own code.

作为旁注,用于Firefox的Selenium IDE也可以突出显示方法.

As a side note, the Selenium IDE for Firefox can highlight methods as well.

这篇关于Selenium Webdriver高亮元素,然后单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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