首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用Selenium将文本发送到div元素中的文本区域

如何使用Selenium将文本发送到div元素中的文本区域
EN

Stack Overflow用户
提问于 2018-05-30 23:40:42
回答 3查看 1.3K关注 0票数 0

如何使用Selenium Automationtextarea框发送文本或提供输入

它是一个带有style="overflow:hidden"div元素。我试过使用XPath,但它对我不起作用。

如何向图中所示的 textarea 提供输入?

EN

回答 3

Stack Overflow用户

发布于 2018-05-31 12:54:42

试试这个:

代码语言:javascript
复制
driver.findElement(By.xpath("//div[@class='input_area']//textarea"))
      .sendKeys("Your Value");
票数 1
EN

Stack Overflow用户

发布于 2018-05-31 00:18:07

我相信你在几件事上搞错了:

  1. 你不是把文本发送到div,而是发送到文本区域。
  2. 文本区域没有隐藏*的样式。这在你提供的截图中是很明显的,父div
  3. 也没有隐藏*的样式。如果有,你就看不到子文本区域了。
  4. style="overflow: hidden"只隐藏了在它的'box‘中看不到的内容,但不隐藏整个元素。

我希望这能帮到你。我建议在进一步尝试自动化页面之前,先温习一下HTML和CSS。

*可能有一个外部CSS文件可以应用隐藏的样式,但由于我们可以在屏幕截图中看到文本区域,我不相信是这种情况。

票数 0
EN

Stack Overflow用户

发布于 2018-06-05 15:21:52

有可能textarea位于其上的父元素位于frame内。请务必检查页面的HTML代码,并查找包装textarea的任何框架。

如果是这样,您可以在执行sendKeys()之前临时切换到帧

driver.switchTo().frame(arg)。您可以从下面的任何签名中进行选择。

代码语言:javascript
复制
/**
 * 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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50608716

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档