JavaScriptexecutor setAttribute value on selenium

后端 未结 1 936
南笙
南笙 2021-01-27 03:34

I was executing a selenium automation on IE11. Now for an Element, say ele; ele.sendKeys(characters) are not working directly. So I was trying to change the \'value

相关标签:
1条回答
  • 2021-01-27 04:26

    You have to instantiate your WebElement after manipulating the DOM, not before. Otherwise the stored WebElement won't contain the information you are looking for and will return null.

    driver.executeScript("document.getElementById('ID').setAttribute('value','NEW_VALUE');");
    System.out.print("value: "+driver.findElement(By.id("ID")).getAttribute("value"));
    
    0 讨论(0)
提交回复
热议问题