I need to edit some readonly
fields with Selenium WebDriver in Java. As Selenium won\'t let me even find this fields I searched for solutions and found that the
WebElement elementName = driver.findElement(By.xpath("//div[@arid='7']//input[@id='arid7']"));
((JavascriptExecutor) driver).executeScript("arguments[0].removeAttribute('readonly','readonly')", elementName);
This worked for me
Apparently there was a very funky character being put into your string.. as I was using my <- and -> arrow keys, it was getting caught for three characters at the end, and in the middle of the string. Seems to be some copy-pasta issue.
I fixed it just be putting it one one line, however I would still recommend going with @lost's answer as it's more explicit.
@Config(url="https://rawgithub.com/ddavison/so-tests/master/22711441.html", browser= Browser.CHROME)
public class _22711441 extends AutomationTest {
@Test
public void test() {
((JavascriptExecutor) driver).executeScript(
// the issue was happening \/ here and \/ here
"var inputs = document.getElementsByTagName('input');for(var i = 0; i < inputs.length; i++){inputs[i].removeAttribute('readonly','readonly');}"
);
setText(By.id("1"), "something")
.validateText(By.id("1"), "something");
}
}
See the script here and the page i used to test here
I was not able to find the issue with your code. But in the meantime use the code given below.
List<WebElement> inputs = driver.findElements(By.tagName("input"));
for (WebElement input : inputs) {
((JavascriptExecutor) driver).executeScript(
"arguments[0].removeAttribute('readonly','readonly')",input);
}
Let me know if this helps you.