多测师是一家拥有先进的教学理念,强大的师资团队,业内好评甚多的接口自动化测试培训机构!

17727591462

联系电话

您现在所在位置:接口自动化测试培训 > 新闻资讯

selenium之高亮对象-自动化测试

更新时间:2022-05-16 09:24:43 作者:多测师 浏览:178

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

selenium之高亮对象-自动化测试

  具体的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);//高亮所定位的对象

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

  以上内容为大家介绍了自动化测试中的selenium之高亮对象,本文由多测师亲自撰写,希望对大家有所帮助。了解更多自动化测试相关知识:https://www.aichudan.com/xwzx/

联系电话

17727591462

返回顶部