Remove readonly attributes in Selenium WebDriver

前端 未结 3 1633
北恋
北恋 2021-01-13 15:21

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

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-13 15:47

    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

提交回复
热议问题