尝试使用selenium在文本区域中编写

6ss1mwsb  于 2021-07-03  发布在  Java
关注(0)|答案(2)|浏览(342)

这个问题在这里已经有答案了

org.openqa.selenium.elementNotInteractiableException:无法通过键盘访问元素:向facebook中的firstname字段发送文本时(4个答案)
24天前关门。
我试图用selenium(java)在instagram上发表评论。instagram评论框 textArea ,如何添加评论?
我做了这个。。。

WebElement cmdbox = driver.findElement(By.tagName("textarea"));
cmdbox.clear();
Thread.sleep(2000);
cmdbox.sendKeys("sample text");
Thread.sleep(3000);

我犯了这个错误

jtw3ybtb

jtw3ybtb1#

抛出ElementNotInteractiableException以指示尽管dom中存在元素,但它不处于可与之交互的状态。
又名它在dom中,但是你还不能点击它。有几种方法可以解决这个问题 ExpectedConditions.elementToBeClickable() 是一种方式。在调用click之前,helper方法可能会有所帮助。

public static void waitForElementClickable(WebDriver webdriver, By by, long timeout) {
    WebDriverWait wait = new WebDriverWait(webdriver, timeout);
    wait.until(ExpectedConditions.elementToBeClickable(by));
  }
thtygnil

thtygnil2#

WebDriverWait wait = new WebDriverWait(webdriver, timeout); //15 can be ideal for timeout

//清除区域的代码

wait.until(ExpectedConditions.elementToBeClickable(By.tagName("textarea"))).clear();

//发送密钥的代码

wait.until(ExpectedConditions.visibilityOfElementLocated(By.tagName("textarea"))).sendKeys("sample text");

如果这不起作用,您可以使用by.cssselector(“textarea.ypffh”)作为by.tagname(“textarea”)的另一种替代方法

相关问题