如何使用seleniumwebdriver在页眉中插入文本
how to insert text in header using selenium webdriver
我有下面的代码,
<body>
<table>
<tr>
<td style= "width:30%;">
<img class = "new" src="images/new-icon.png">
<td>
<h1>Hello there!</h1>
<p>Thanks for logging in
<span class = "blue">image edit application</span>.
Get started by reading our
<a href = "https:abc">documentation</a>
or use the xxxxxxxxxxxx.
</table>
</body>
在上面的代码中,我想使用带有java脚本的selenium webdriver在
标题中的"Hello there!"之后添加额外的文本。请帮忙。我试着点击Hello,用xpath定位它,并尝试用sendKeys添加文本。我没有看到任何添加的文本,代码也没有抛出任何错误。我正在尝试使用selenium 在在线编辑器上编辑html文件
尝试使用executeScript()
函数在浏览器中执行JS。您必须编写一个JavaScript代码来附加/替换文本。
我不熟悉Selenium with JS,但这是一个可以尝试的粗略代码。
script = "theParent = document.getElementByTagName('body');
theKid = document.createElement('div');
theKid.innerHTML = 'Hello There!';
// append theKid to the end of theParent
theParent.appendChild(theKid);
// prepend theKid to the beginning of theParent
theParent.insertBefore(theKid, theParent.firstChild);"
driver.executeScript('return ' + script).then(function(return_value) {
console.log('returned ', return_value);
});
相关文章:
- 我可以在网页正文中插入文本链接吗
- 使用.format在一些HTML代码中插入文本,会出现错误(Python)
- 将href类插入JS文件(使用createLink)任何想法
- 使用 Greasemonkey 在现有元素之前插入文本节点时出现问题
- 使用 jQuery/Javascript 将鼠标悬停在按钮上时将文本插入文本和帮助文本
- 如何使用 Javascript 插入文本框
- 如何使用 DOM-Methods 在 JavaScript 调用的位置插入文本
- 使用Javascript将鼠标点击坐标插入文本输入框
- 使用Regex在字符串模式出现前后插入文本
- 使用CKEditor插入文本(软连字符)的快捷键
- 使用 jQuery 在悬停时插入文本,并从左向右滑动
- 在“”之后插入文本;这个“;使用javascript输入元素
- 使用javascript为谷歌chrome扩展插件将文本插入文本区域
- 如何使用seleniumwebdriver在页眉中插入文本
- 使用javascript在HTML标签中插入文本
- 使用js向db插入文本时出现问题
- 使用javascript在输入字段中插入文本
- 复选框使用Javascript将文本插入文本区域
- 使用Quill.js在光标位置插入文本
- 使用jQuery在现有文本框内容之前插入文本