频道栏目
首页 > 资讯 > 其他综合 > 正文

Selenium执行操作时高亮对象

17-03-30        来源:[db:作者]  
收藏   我要投稿
Selenium执行操作时高亮对象:希望下面的文章对大家有所帮助。
package com.gloryroad.testcase;

import org.openqa.selenium.By;

import org.openqa.selenium.JavascriptExecutor;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;

import com.gloryroad.Demo.JavaScriptExcutor;

public class TestHighLightWebElement {

public WebDriver driver;

private String url="http://www.sogou.com";

public JavascriptExecutor js;

@BeforeMethod

public void setUp(){

driver=new FirefoxDriver();

driver.get(url);

}

@AfterMethod

public void tearDown(){

driver.close();

}

@Test

public void testHighLigthWebdriver(){

WebElement searchInput=driver.findElement(By.id("query"));

WebElement submitButton=driver.findElement(By.id("stb"));

highLightElement(searchInput);

searchInput.sendKeys("Good");

highLightElement(submitButton);

submitButton.click();

}

public void highLightElement(WebElement element){

js=(JavascriptExecutor) driver;

for (int i = 0; i < 3; i++) {

js.executeScript("arguments[0].setAttribute('style',arguments[1]);", element,"background:yellow ;border:3px solid green;");

try {

Thread.sleep(1000);

js.executeScript("arguments[0].removeAttribute('style',arguments[1]);", element,"background:yellow ;border:3px solid green;");

} catch (Exception e) {

// TODO: handle exception

}

}

}

}

 

相关TAG标签
上一篇:java web个人博客开发(三数据结构设计)
下一篇:JavaSelenium的截图对比代码
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站