[英]How to Disable a TextBox in Selenium
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 );
For disable text box , you need to set .disabled
property of the textbox
to true
as below :- 对于禁用的文本框 ,你需要设置
.disabled
的财产textbox
,以true
如下: -
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement textbox = driver.findElement(By.id("textbox"));
js.executeScript("arguments[0].disabled = true", textbox);
JavascriptExecutor javascript = (JavascriptExecutor) driver;
String todisable = "document.getElementsById('textbox')[0].setAttribute('disabled', '');";
javascript.executeScript(todisable);
To disable the textbox in javascript you can do: 要禁用javascript中的文本框,您可以执行以下操作:
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.getElementById('textbox').setAttribute('disabled', '');");
JavascriptExecutor js=(JavascriptExecutor)driver;
js.executeScript("document.getElementById('name').value='singh'");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.