如何在java selenium中更改注释的名称属性值
我在java selenium中有一个注释如何在java selenium中更改注释的名称属性值,java,selenium,annotations,Java,Selenium,Annotations,我在java selenium中有一个注释 注释 @FindBy(name= "passFirst0" ) public WebElement txtPassengerFirstName; public static void setAttribute(RemoteWebDriver rmtDriver, WebElement element, String attName, String attValue) { try { rmtDr
注释
@FindBy(name= "passFirst0" )
public WebElement txtPassengerFirstName;
public static void setAttribute(RemoteWebDriver rmtDriver, WebElement element,
String attName, String attValue) {
try {
rmtDriver.executeScript("arguments[0].setAttribute(arguments[1], arguments[2]);", element, attName, attValue);
} catch (NoSuchElementException e) {
System.out.println(e);
}
}
我想将运行时测试应用程序页面上的另一个文本框的属性“name”值更改为“passFirst1”,并为其分配一个数据值。我写了两个相同的代码,但都不工作
public static void setAttribute(RemoteWebDriver rmtDriver, WebElement element,
String attName, String attValue) {
try {
rmtDriver.executeScript("arguments[0].setAttribute(arguments[1], arguments[2]);", element, attName, attValue);
} catch (NoSuchElementException e) {
System.out.println(e);
}
}
第一个:
String strModifiedNameAttribute = txtPassengerFirstName.getAttribute("name");
strModifiedNameAttribute = strModifiedNameAttribute.replace("0", "");
strModifiedNameAttribute = strModifiedNameAttribute + i;
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].setAttribute('name', '" + strModifiedNameAttribute + "' )", txtPassengerFirstName);
txtPassengerFirstName.sendKeys("Amit");
public static void setAttribute(RemoteWebDriver rmtDriver, WebElement element,
String attName, String attValue) {
try {
rmtDriver.executeScript("arguments[0].setAttribute(arguments[1], arguments[2]);", element, attName, attValue);
} catch (NoSuchElementException e) {
System.out.println(e);
}
}
第二个
String strModifiedNameAttribute = txtPassengerFirstName.getAttribute("name");
strModifiedNameAttribute = strModifiedNameAttribute.replace("0", "");
strModifiedNameAttribute = strModifiedNameAttribute + i;
exampleUsage(rmtDriver, txtPassengerFirstName, "name", strModifiedNameAttribute);
txtPassengerFirstName.sendKeys("Amit");
public static void exampleUsage(RemoteWebDriver rmtDriver, WebElement element,
String strAttributeName, String strAttributeValue) {
setAttribute(rmtDriver, element, strAttributeName, strAttributeValue);
}
public static void setAttribute(RemoteWebDriver rmtDriver, WebElement element,
String attName, String attValue) {
try {
rmtDriver.executeScript("arguments[0].setAttribute(arguments[1], arguments[2]);", element, attName, attValue);
} catch (NoSuchElementException e) {
System.out.println(e);
}
}
调用setAttribute的方法
String strModifiedNameAttribute = txtPassengerFirstName.getAttribute("name");
strModifiedNameAttribute = strModifiedNameAttribute.replace("0", "");
strModifiedNameAttribute = strModifiedNameAttribute + i;
exampleUsage(rmtDriver, txtPassengerFirstName, "name", strModifiedNameAttribute);
txtPassengerFirstName.sendKeys("Amit");
public static void exampleUsage(RemoteWebDriver rmtDriver, WebElement element,
String strAttributeName, String strAttributeValue) {
setAttribute(rmtDriver, element, strAttributeName, strAttributeValue);
}
public static void setAttribute(RemoteWebDriver rmtDriver, WebElement element,
String attName, String attValue) {
try {
rmtDriver.executeScript("arguments[0].setAttribute(arguments[1], arguments[2]);", element, attName, attValue);
} catch (NoSuchElementException e) {
System.out.println(e);
}
}
SetAttribute方法
public static void setAttribute(RemoteWebDriver rmtDriver, WebElement element,
String attName, String attValue) {
try {
rmtDriver.executeScript("arguments[0].setAttribute(arguments[1], arguments[2]);", element, attName, attValue);
} catch (NoSuchElementException e) {
System.out.println(e);
}
}
请帮助我在运行时更改name属性值,以便我可以为其分配一个数据值。那么您要做的是使用Selenium修改页面上的HTML?或者您正在尝试与屏幕上的两个对象(firstPass0和firstPass1)进行交互,并更新这两个对象?或者您正在尝试与屏幕上的两个对象(firstPass0和firstPass1)交互,并更新这两个对象。
public static void setAttribute(RemoteWebDriver rmtDriver, WebElement element,
String attName, String attValue) {
try {
rmtDriver.executeScript("arguments[0].setAttribute(arguments[1], arguments[2]);", element, attName, attValue);
} catch (NoSuchElementException e) {
System.out.println(e);
}
}