当我想获取属性类型" textArea"
时,我遇到了WebDriver Java类的问题我得到了这个例外。
代码:
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");
例外:
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)
答案 0 :(得分:0)
它无法正常工作的原因是需要输入文本的元素位于iframe中。请尝试以下代码:
driver.switchTo().frame(
driver.findElements(By.tagName("iframe")).get(0));
WebElement descriptionOne = driver
.findElement(By.className("editbox"));
descriptionOne.sendKeys("Hola! :D");
答案 1 :(得分:0)
根据您的代码,您在给sendkey调用错误的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");
请使用“ descriptionOne.sendKeys(“ Hola!:D”);“而不是“ descripcionUno.sendKeys(“ Hola!:D”);“
让我知道它是否对您有用。干杯!