[英]org.openqa.selenium.NoSuchElementException WebDriver in Java?
I have a problem with WebDriver Java class, when I want to get an attribute type "textArea" 当我想要获取属性类型“ textArea”时,WebDriver Java类出现问题
I get this Exception. 我得到这个异常。
Code: 码:
WebDriver driver = new HtmlUnitDriver();
driver.get("http://www.cmmazzoni.it/index.php?option=com_jdownloads&Itemid=0&view=upload");
WebElement descriptionOne=driver.findElement(By.name("description"));
descripcionUno.sendKeys("Hola! :D");
Exception: 例外:
java.lang.UnsupportedOperationException: You may only set the value of elements that are input elements
at org.openqa.selenium.htmlunit.HtmlUnitKeyboard.sendKeys(HtmlUnitKeyboard.java:82)
at org.openqa.selenium.htmlunit.HtmlUnitWebElement.sendKeys(HtmlUnitWebElement.java:343)
at Modelo.HiloPaginas.subibirImagencom_jdownloads(HiloPaginas.java:219)
at Modelo.HiloPaginas.run(HiloPaginas.java:108)
The reason it ain't working is cause the element where u need to enter text is in a iframe. 它无法正常工作的原因是,您需要在其中输入文本的元素位于iframe中。 Please try out following code:
请尝试以下代码:
driver.switchTo().frame(
driver.findElements(By.tagName("iframe")).get(0));
WebElement descriptionOne = driver
.findElement(By.className("editbox"));
descriptionOne.sendKeys("Hola! :D");
As per your code, you are calling wrong webElement name to sendkeys: 根据您的代码,您在给sendkeys调用错误的webElement名称:
WebDriver driver = new HtmlUnitDriver();
driver.get("http://www.cmmazzoni.it/index.php?option=com_jdownloads&Itemid=0&view=upload");
WebElement descriptionOne=driver.findElement(By.name("description"));
descripcionUno.sendKeys("Hola! :D");
Please use "descriptionOne.sendKeys("Hola! :D");" 请使用“ descriptionOne.sendKeys(“ Hola!:D”);“ instead of "descripcionUno.sendKeys("Hola! :D");"
而不是“ descripcionUno.sendKeys(“ Hola!:D”);“
Let me know if it works for you. 请让我知道这对你有没有用。 Cheers!
干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.