猿问

无法将键发送到 div 元素 Selenium - Java

我正在尝试使用 xpath 将值填充到文本框(检查下面的图片)。


Actions actions = new Actions(driver);

                                        actions.moveToElement(driver.findElement(By.xpath("//*[@class='CzI8E']")));

                                        actions.click();

                                        Thread.sleep(3000);

                                        actions.moveToElement(driver.findElement(By.xpath("//*[@class='_2S1VP copyable-text selectable-text']")));//_2S1VP copyable-text selectable-text

                                        actions.sendKeys(WhatsappConstants.TEXT_MESSAGE);

                                        actions.build().perform();

但我得到这个例外


org.openqa.selenium.WebDriverException: unknown error: ChromeDriver only supports characters in the BMP


其他stackoverflow答案说使用firefox驱动程序,但在我的情况下,我只需要使用chrome。

扬帆大鱼
浏览 179回答 2
2回答

交互式爱情

我有一个类似的问题,我以这种方式解决了它。首先,您应该使用 向此 div 添加任何文本JavascriptExecutor ,然后清除此文本并使用 selenium 的sendKeys方法WebElement inputDiv = driver.findElement(By.xpath("your_path_to_div"));JavascriptExecutor executor = (JavascriptExecutor) driver;executor.executeScript("document.querySelector('your_selector_to_div').innerText='aaa'");inputDiv.clear();inputDiv.sendKeys(subject);
随时随地看视频慕课网APP

相关分类

Java
我要回答