如何将文本添加到任何 html 元素? [英] How to add text to any html element?

查看:27
本文介绍了如何将文本添加到任何 html 元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向 body 元素添加文本,但我不知道如何添加.哪种方法适用于 body 标签?抱歉我的英语不好,感谢您的回复.

I want to add text to body element but I don't know how. Which method will work on the body tag? Sorry for my english and thanks for replies.

推荐答案

在 Watir 中,您可以使用 JS 操作网页 (DOM),就像这样:

In Watir, you can manipulate a web page (DOM) using JS, just like that:

 browser.execute_script("document.getElementById('pageContent').appendChild(document.createTextNode('Great Success!'));")

我认为问题的重点是:所有用户都不仅仅是通过点击 Web 应用程序上的按钮和链接来进行交互,他们中的一些人正在做一些讨厌的事情,比如改变 http 请求,让你的系统做一些它不应该做的事情......或者只是为了找点乐子.

I assume that the point of the question is: All users are not just interacting by just clicking buttons and links on the web app, some of them are doing nasty things like altering http requests to make your system do something that it is not supposed to do... or to just have some fun.

要模仿这种行为,您可以编写一个 ui-test 来更改网页上的表单,例如,您可以在任何字段中输入任何内容,而不是有限的下拉列表.

To mimic this behavior, you could write a ui-test that alters forms on the web page, so that for example, one could type in anything into any field instead of a limited dropdown.

要做到这一点,用户界面测试必须:

To do that, ui test has to:

  • 操纵 DOM 以不受限制地设置表单输入(将选择替换为输入等)
  • ui test 必须知道要使用哪些值,在许多情况下输入随机值毫无意义.您的网络应用必须提供一些好的不需要的"选项.

这篇关于如何将文本添加到任何 html 元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆