【问题标题】:How to get Javascript to execute when clicking a button in IEAutomation?单击 IEAutomation 中的按钮时如何执行 Javascript?
【发布时间】:2012-05-25 12:18:48
【问题描述】:

我在 perl 中使用Win32::IEAutomation 来填写表格和搜索,但是当我使用getButton()->Click 时,我收到错误"Can't call method "Click" on an undefined value"。我可以单击图像(执行 javascript),但不能单击按钮。我在Win32::IEAutomation 的文档中注意到它在“getImage”和“getLink”下都有以下内容,但在“getButton”下没有:

"由于使用了DOM的click方法,所以支持点击里面有javascript的链接。"

谁能告诉我如何点击按钮并触发 javascript?

这是我的代码框架。最后一行是给我带来麻烦的那一行。:

use Win32::IEAutomation;
my $ie = Win32::IEAutomation->new( visible => 1);
$ie->gotoURL('https://www.mywebpage.com/index.html',1);

$ie->getTextBox('id:', "mytextbox")->SetValue("relevant text");
$ie->getButton('id:', "mybutton")->Click;

这里是html的相关部分:

<input type="text" id="mytextbox" />
<button id="mybutton" title="Go" class="ControlButton" value="Go" onclick="researchLookupObj.GoClick(CallServer);return false;">Search</button>

我可以让文本框填写(并且可以单击此处未显示的代码中前面的图像),但使用按钮时出现错误。如何告诉它执行名为“researchLookupObj.GoClick()”的 javascript?

【问题讨论】:

  • 可能是 IE 的问题。当我使用 WatiN 进行测试时,有时我不得不强制它等待并评估函数:(

标签: javascript perl internet-explorer button


【解决方案1】:

我建议您使用WWW::Scripter 来完成此任务。它可能更适合您。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-12
    • 1970-01-01
    相关资源
    最近更新 更多