I have a problem with WebDriver Java class, when I want to get an attribute type "textArea" 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)
Code HTML:
<td width="140" valign="top">Descripción Corta:
</td><td width="20" valign="top"> </td></tr>
<tr><td colspan="3">
<textarea cols="75" rows="20" style="width:100%; height:350px;" id="description" name="description"></textarea>
<script type="text/javascript">window.addEvent("domready",function()
{CKEDITOR.config.expandedToolbar = true;
Replacedescription_longTextContainer("description");
});
</script><
</td>
It would seem that the name
value you are passing to your selenium driver and the name
property you are setting up do not match.
Change this: WebElement descriptionOne=driver.findElement(By.name("description"));
to this: WebElement descriptionOne=driver.findElement(By.name("description_long"));
It is best for you to use id when it is possible. If element does not have an id then you may use the "cssselector". You just write down the jquery as a parameter to,
driver.findElement(By.cssSelector("jquery"));
For your problem;
driver.findElement(By.id("description"));
driver.findElement(By.cssSelector("#description"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.