簡體   English   中英

org.openqa.selenium.NoSuchElementException WebDriver是否在Java中?

[英]org.openqa.selenium.NoSuchElementException WebDriver in Java?

當我想要獲取屬性類型“ 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)

它無法正常工作的原因是,您需要在其中輸入文本的元素位於iframe中。 請嘗試以下代碼:

driver.switchTo().frame(
        driver.findElements(By.tagName("iframe")).get(0));
WebElement descriptionOne = driver
    .findElement(By.className("editbox"));
descriptionOne.sendKeys("Hola! :D");

根據您的代碼,您在給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");

請使用“ descriptionOne.sendKeys(“ Hola!:D”);“ 而不是“ descripcionUno.sendKeys(“ Hola!:D”);“

請讓我知道這對你有沒有用。 干杯!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM