(Selenium WebDriver) get Value in disabled element and set Value in readonly element using javaScript
nomally you can get attribute data in element using below code
driver.findElement(By.id(elmentName)).getAttribute("attributeName")
but in case the element is readonly or disabled, you cannot. (at least i cannot) so I used javaScript!
you can also use javaScript when you are using Selenium like
((JavascriptExecutor)driver).executeScript(String script, Object... args)
here are my code.
- get value in disabled element
((JavascriptExecutor) driver).executeScript("return document.getElementById('elementName').value;",""));
- set value in readonly element
String data = "Hello World"
WebElement element = driver.findElement(By.name(elementName));
((JavascriptExecutor) driver).executeScript("arguments[0].value=arguments[1]", element, data);
댓글 없음:
댓글 쓰기