您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源功能測(cè)試工具 > Selenium
selenium之高亮對(duì)象
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/8/29 15:10:38 ] 推薦標(biāo)簽:

  給大家分享一個(gè)高亮對(duì)象的方法,這個(gè)方法不止適用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中調(diào)用該js

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

  建議:希望大家把不同的東西放在不同包里面,這樣有利于后期的維護(hù)

軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd