使用selenium给更改页面元素的css属性

package com.gloryroad.Demo;


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;


public class setAttribuateAndRmoveAttr {


String url="http://127.0.0.1:8020/HTMLDemo/HTMLPDir/Temp02/framecen.html";
public WebDriver driver;
@BeforeMethod
public void setUp(){
driver=new FirefoxDriver();
driver.get(url);

}

@AfterMethod
public void tearDown(){
driver.close();
}
@Test
public void testPicker()
{
WebElement  textInputbox=driver.findElement(By.id("text"));
setAttribuate(textInputbox, "size", "10");
removeAttribuate(textInputbox, "size", "10");

}
public void setAttribuate(WebElement eleemnt,String attrName,String attrValue){


((JavascriptExecutor)driver).executeScript("arguments[0].setAttribute(arguments[1],arguments[2])", eleemnt,attrName,attrValue);

}

public void removeAttribuate(WebElement eleemnt,String attrName,String attrValue)
{
((JavascriptExecutor)driver).executeScript("arguments[0].removeAttribute(arguments[1],arguments[2])", eleemnt,attrName,attrValue);

}

}

你可能感兴趣的:(Java编程,测试经验总结)