admin管理员组文章数量:1422437
I am trying to sendkeys to an input,but I don't know why it warns me like this:
org.openqa.selenium.InvalidElementStateException: Element must not be hidden, disabled or read-only (WARNING: The server did not provide any stacktrace information)
The HTML page source:
<span id="mini-7" class="mini-textbox mini-textbox-empty" style="border-width: 0pt; width: 342px;">
<input class="mini-textbox-input" type="text" autoplete="off" style="width: 338px;">
<input type="hidden">
</span>
My code:
driver.findElement(By.cssSelector("#mini-7 > input.mini-textbox-input")).clear();
driver.findElement(By.cssSelector("#mini-7 > input.mini-textbox-input")).sendKeys("yy");
Then I change my code like this:
JavascriptExecutor jse = (JavascriptExecutor)driver;
((JavascriptExecutor) jse).executeScript("arguments[0].type ='text';",driver.findElement(By.xpath("//span[@id='mini-7']/input[2]")));
But this time it throws out js error. Why?
I use sendkeys to the first input,this input is not hidden
I am trying to sendkeys to an input,but I don't know why it warns me like this:
org.openqa.selenium.InvalidElementStateException: Element must not be hidden, disabled or read-only (WARNING: The server did not provide any stacktrace information)
The HTML page source:
<span id="mini-7" class="mini-textbox mini-textbox-empty" style="border-width: 0pt; width: 342px;">
<input class="mini-textbox-input" type="text" autoplete="off" style="width: 338px;">
<input type="hidden">
</span>
My code:
driver.findElement(By.cssSelector("#mini-7 > input.mini-textbox-input")).clear();
driver.findElement(By.cssSelector("#mini-7 > input.mini-textbox-input")).sendKeys("yy");
Then I change my code like this:
JavascriptExecutor jse = (JavascriptExecutor)driver;
((JavascriptExecutor) jse).executeScript("arguments[0].type ='text';",driver.findElement(By.xpath("//span[@id='mini-7']/input[2]")));
But this time it throws out js error. Why?
I use sendkeys to the first input,this input is not hidden
Share Improve this question edited Apr 2, 2013 at 4:43 user2027659 asked Dec 25, 2012 at 5:36 怡 许怡 许 211 gold badge1 silver badge2 bronze badges 3- did you try with capitalized "HIDDEN" ? IE has some issues – cppanda Commented Dec 25, 2012 at 5:47
- I fixed it ,just like this:JavascriptExecutor jse = (JavascriptExecutor)driver; ((JavascriptExecutor) jse).executeScript("arguments[0].style.visibility = 'visible';",driver.findElement(By.xpath("//span[@id='mini-7']/input"))); but i still donot know why – 怡 许 Commented Dec 25, 2012 at 8:26
- What language did you use? Java? C#? or what? – Ripon Al Wasim Commented Jan 22, 2013 at 11:32
3 Answers
Reset to default 1That input could still have css property visibility: hidden
or display: none
. That's what exception is telling you. Check all the properties with browser's dev tools.
First of all it needs to change the value of type attribute as text from hidden. Now, you are able to type on that text by using WebDriver. So, the overall code for typing with WebDriver using Java and Javascript as follows:
WebDriver driver = new FirefoxDriver();
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("document.getElementById('mini-7').setAttribute('type', 'text');");
driver.findElement(By.cssSelector("#mini-7 > input.mini-textbox-input")).clear();
driver.findElement(By.cssSelector("#mini-7 > input.mini-textbox-input")).sendKeys("yy");
For 1st input field which is not hidden, use absolute path for cssSelector.
What you can do in this case is making the element visible by modifying the css tag for
visibility: hidden
or
display: none
using javascript just before sending keys to it.
本文标签: javascriptHow to type text on hidden text box in WebDriver with JavaStack Overflow
版权声明:本文标题:javascript - How to type text on hidden text box in WebDriver with Java - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745343111a2654355.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论