qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

selenium之高亮对象

今天给大家分享一个高亮对象的方法,这个方法不止适用selenium,只要你是用java编写代码,其都可以

  具体的js代码

package js;//该class在js包中
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
// Highlight WebElement
public class Highlight {
public void highlightElement(WebDriver driver, WebElement element) {
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("element = arguments[0];" +
"original_style = element.getAttribute('style');" +
"element.setAttribute('style', original_style + \";" +
"background: yellow; border: 2px solid red;\");" +
"setTimeout(function(){element.setAttribute('style', original_style);}, 1000);", element);
}
}

  在具体的class中调用该js

import js.Highlight;//引入需要的js文件
WebElement sche= driver.findElement(By.name("preschedule"));//对位对象
Highlight hi=new Highlight();
hi.highlightElement(driver,sche);//高亮所定位的对象

  建议:希望大家把不同的东西放在不同包里面,这样有利于后期的维护

 

posted on 2013-08-30 09:47 顺其自然EVO 阅读(790) 评论(0)  编辑  收藏 所属分类: selenium and watir webdrivers 自动化测试学习


只有注册用户登录后才能发表评论。


网站导航:
 
<2013年8月>
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜