Reputation: 944
I tried to disabled a textbox, but it doesn't work as expected. The following is my code
the disabling command:
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement textbox = driver.findElement(By.id("textbox"));
js.executeScript("arguments[0].setAttribute('disabled', '');", textbox );
the testing command:
js.executeScript("arguments[0].setAttribute('value', 'Text Box Enalbled !! ');", textbox );
Upvotes: 0
Views: 1616
Reputation: 1
JavascriptExecutor js=(JavascriptExecutor)driver;
js.executeScript("document.getElementById('name').value='singh'");
Upvotes: 0
Reputation:
To disable the textbox in javascript you can do:
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.getElementById('textbox').setAttribute('disabled', '');");
Upvotes: 1
Reputation: 23805
For disable text box, you need to set .disabled
property of the textbox
to true
as below :-
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement textbox = driver.findElement(By.id("textbox"));
js.executeScript("arguments[0].disabled = true", textbox);
Upvotes: 2
Reputation: 11251
JavascriptExecutor javascript = (JavascriptExecutor) driver;
String todisable = "document.getElementsById('textbox')[0].setAttribute('disabled', '');";
javascript.executeScript(todisable);
Upvotes: 1