Java自动化测试系列(修改页面元素属性)
程序员文章站
2023-04-03 17:31:09
只有干货,源码奉上,请无限扩展...
package Util; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; /**
* Summary: add/modify/delete attribute of elements
*
* @author: davieyang
* @create: 2018-08-05 2:29
*/ public class ModifyElementsAttributeByJS { public void setAttribute(WebDriver driver, WebElement element, String attributeName, String value){ JavascriptExecutor js = (JavascriptExecutor) driver; /**
* 调用js修改页面元素的属性值arguments[0]-arguments[2]会由element,attributeName,value替换
*/ js.executeScript("arguments[0].setAttribute(arguments[1],arguments[2])", element,attributeName,value); } public void removeAttribute(WebDriver driver, WebElement element, String attributeName){ JavascriptExecutor js = (JavascriptExecutor) driver; /**
* 调用js修改页面元素的属性值arguments[0]-arguments[1]会由element,attributeName替换
*/ js.executeScript("arguments[0].removeAttribute(arguments[1],arguments[2])", element,attributeName); } }
本文地址:https://blog.csdn.net/dawei_yang000000/article/details/108019774
上一篇: mybatis-plus如何使用的一些问题经验总结
下一篇: 如何利用百度文库做推广?