0

In enterfirstname is a WebElement and it has some value already and I want to store that value pass on same input box element Any help ?

String getfirstname= enterfirstname.getAttribute("value");
System.out.println(getfirstname);
enterfirstname.clear();
enterfirstname.sendKeys(getfirstname);
Prophet
  • 32,350
  • 22
  • 54
  • 79
  • Can you please specify in a little more detail, what do you actually want to extract from the web element (attribute or the content inside the element)? Because if you just want to fetch the value of the attribute from the element, then the above code seems to be correct. – heethjain21 May 04 '21 at 18:09

1 Answers1

0

In case enterfirstname is an input element it's possible (not always) to set it's value by sending text to it.
Otherwise try this:

public void setAttribute(WebElement element, String att, String value){
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.ExecuteScript("arguments[0].setAttribute(arguments[1], arguments[2]);", element, att, value);
}

where element is your WebElement, att is attribute you wish to set (here it is value) and value is a value you want to set.
See here for more details

Prophet
  • 32,350
  • 22
  • 54
  • 79
  • but i am taking getattribute method to store that old value in a string and i want that value in input box in your suggestion you are taking a value name can you guide me that – ankush singh May 05 '21 at 05:51
  • No, I described hot to SET the attribute value. To take the attribute value is simple and you doing it correctly – Prophet May 05 '21 at 06:00