码迷,mamicode.com
首页 > 其他好文 > 详细

1、Selenium执行操作时高亮对象

时间:2020-02-09 18:22:57      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:exception   java   tca   对象   selenium   tor   testng   javascrip   mit   

package com.zengfh.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.zengfh.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) {

}
}

}

}

1、Selenium执行操作时高亮对象

标签:exception   java   tca   对象   selenium   tor   testng   javascrip   mit   

原文地址:https://www.cnblogs.com/zengfh/p/12287883.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!