- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好的,我正在尝试在没有表单的 html 页面上填写输入字段,出于特定原因,我正在尝试解决此问题,并且只需要按照我尝试的方式进行。
基本上这是我的html
<tr>
<td valign="top" nowrap width="120">Amount: <font size="2" color="#CC0000">*</font> </td>
<td width="490">
<input type="text" name="data" size="20" maxlength="20" value="">
<select name="Percent"><option value="2" >NUM</option><option value="1" >num2</option><option value="3" selected>resultin</option></select>
<div class="error"></div>
</td>
</tr>
<td width="490">
<input type="text" name="account" id="account" size="20" maxlength="20" value="">
</td>
现在,当我使用它在帐户字段中插入文本时,一切正常
if(casper.exists(ac1)){
var uel = "https://example.com";
this.thenOpen(uel, function() {
casper.wait(10000, function() {
casper.then(function() {
this.evaluate(function() {
document.getElementById('account').value = '345de';
});
casper.wait(10000, function() {
casper.then(function() {
this.capture("filenadfgmedsfg.jpg");
var el2 = this.getHTML();
fs.write('results23.html', el2, 'w');
});
});
});
但是当我尝试下面的任何一个来填充输入数据字段时,我无法让它工作
if(casper.exists(ac1)){
var uel = "https://example.com";
this.thenOpen(uel, function() {
casper.wait(10000, function() {
casper.then(function() {
this.evaluate(function() {
document.getElementById('data').value = '345de';
});
casper.wait(10000, function() {
casper.then(function() {
this.capture("filenadfgmedsfg.jpg");
var el2 = this.getHTML();
fs.write('results23.html', el2, 'w');
});
});
});
这个不行请帮我解决这个问题
if(casper.exists(ac1)){
var uel = "https://example.com";
this.thenOpen(uel, function() {
casper.wait(10000, function() {
casper.then(function() {
this.evaluate(function() {
document.getElementByName('data').value = '345de';
});
casper.wait(10000, function() {
casper.then(function() {
this.capture("filenadfgmedsfg.jpg");
var el2 = this.getHTML();
fs.write('results23.html', el2, 'w');
});
});
});
谁能告诉我一种使用更简单的 getElementBy 技术填充数据字段的方法
最佳答案
没有方法 getElementByName()
。您可能想要的是 getElementsByName()
,它返回一个元素列表,而不仅仅是一个元素,因此您要么只获取列表中的第一个项目,要么处理整个列表(取决于什么你想做什么)。
var uel = "https://example.com";
this.thenOpen(uel, function () {
casper.wait(10000, function () {
casper.then(function () {
this.evaluate(function () {
document.getElementsByName('data')[0].value = '345de';
});
});
});
});
关于javascript - casperjs getelementbyid 工作但 getelementbyname 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22585072/
这个简单的JS无法设置“para”的值。我猜 getElementByName 不起作用。但为什么? function fn() { document.getElementById("
我需要通过网络浏览器填写输入。当我尝试填写时出现 System.ArgumentOutOfRangeException 错误。我如何填写这个输入区域? 这是我的代码 webBrowser1.Docu
这个问题在这里已经有了答案: JavaScript getElementByName doesn't work (4 个答案) 关闭 3 年前。 如果没有选择文件,我想要提醒。但是在这段代码中当一个
我想在 javascript 元素上创建一个循环,我的 html 是: 而 javascript 是 window.onload = function() { var x = docum
我一直在尝试创建一个隐藏元素,并且想使用隐藏元素的值作为 if 语句的条件。 var x = document.createElement('input'); x.type = 'h
这是我的js函数 function toggleCountry(country) { var elem = document.getElementsByName(country)[0].val
我正在使用jQuery Validation plugin并尝试验证两个时间字段。我想确保如果一个字段选择“全部”,则另一字段也适用,并且结束时间大于开始时间 这是 HTML: All
好的,我正在尝试在没有表单的 html 页面上填写输入字段,出于特定原因,我正在尝试解决此问题,并且只需要按照我尝试的方式进行。 基本上这是我的html Amount: *
document.getElementById('frmMain').elements 我可以这样使用吗 document.getElementByName('frmMain').elements 或
今天我在 IE9 上发现了一个奇怪的行为。(我正在开发一个旧的应用程序,该应用程序在 IE9 上运行良好,以使其与 Firefox 和 Chrome 兼容)我编写了这段代码。
我在 IE9 和 Firefox 上都可以正常使用这段代码,但现在它只能在 Firefox 上运行,并且不会在 IE9 上执行 Java 验证部分。知道我需要做什么才能使其在两种类型的浏览器上运行吗?
我是一名优秀的程序员,十分优秀!