如何使用Selenium Automation向textarea
框发送文本或提供输入
它是一个带有style="overflow:hidden"
的div
元素。我试过使用XPath,但它对我不起作用。
如何向图中所示的 textarea
提供输入?
发布于 2018-05-31 12:54:42
试试这个:
driver.findElement(By.xpath("//div[@class='input_area']//textarea"))
.sendKeys("Your Value");
发布于 2018-05-31 00:18:07
我相信你在几件事上搞错了:
style="overflow: hidden"
只隐藏了在它的'box‘中看不到的内容,但不隐藏整个元素。我希望这能帮到你。我建议在进一步尝试自动化页面之前,先温习一下HTML和CSS。
*可能有一个外部CSS文件可以应用隐藏的样式,但由于我们可以在屏幕截图中看到文本区域,我不相信是这种情况。
发布于 2018-06-05 15:21:52
有可能textarea
位于其上的父元素位于frame
内。请务必检查页面的HTML代码,并查找包装textarea
的任何框架。
如果是这样,您可以在执行sendKeys()
之前临时切换到帧
driver.switchTo().frame(arg)
。您可以从下面的任何签名中进行选择。
/**
* Select a frame by its (zero-based) index. Selecting a frame by index is equivalent to the
* JS expression window.frames[index] where "window" is the DOM window represented by the
* current context. Once the frame has been selected, all subsequent calls on the WebDriver
* interface are made to that frame.
*
* @param index (zero-based) index
* @return This driver focused on the given frame
* @throws NoSuchFrameException If the frame cannot be found
*/
WebDriver frame(int index);
/**
* Select a frame by its name or ID. Frames located by matching name attributes are always given
* precedence over those matched by ID.
*
* @param nameOrId the name of the frame window, the id of the <frame> or <iframe>
* element, or the (zero-based) index
* @return This driver focused on the given frame
* @throws NoSuchFrameException If the frame cannot be found
*/
WebDriver frame(String nameOrId);
/**
* Select a frame using its previously located {@link WebElement}.
*
* @param frameElement The frame element to switch to.
* @return This driver focused on the given frame.
* @throws NoSuchFrameException If the given element is neither an IFRAME nor a FRAME element.
* @throws StaleElementReferenceException If the WebElement has gone stale.
* @see WebDriver#findElement(By)
*/
WebDriver frame(WebElement frameElement);
https://stackoverflow.com/questions/50608716
复制相似问题