---
title: "Watir: How can I execute in a watir script a specific javascript function called"
author: "lilingjay"
date: "2012-04-01T14:43:50Z"
tags: []
categories: ["开源软件"]
slug: "watir-how-can-i-execute-in-a-watir-script-a-specific-javascript-function-called"
draft: false
lastmod: "2012-03-31T23:41:23Z"
id: 1472024
url: "https://lilingjay.iteye.com/blog/1472024"
---

原地址 [http://stackoverflow.com/questions/6051786/watir-how-can-i-execute-in-a-watir-script-a-specific-javascript-function-called](http://stackoverflow.com/questions/6051786/watir-how-can-i-execute-in-a-watir-script-a-specific-javascript-function-called)

 

Question

 

 

In a Watir script, after I check checkboxes in a popup window, I'm trying to execute a javascript function to add objects selected to the parent window.

What works fine until now it is the check of the checkbox, but object is not added to the parent window and I get following error when I executed the watir script: in \`method\_missing': execScript (WIN32OLERuntimeError)

This was my approach - please let me know what other method I can use

```
ie.checkbox(:id => "check_asm0option0").set 
ie.document.parentWindow.execScript("window.triggerOriginalChange(asm0option0, add);","JavaScript") 

tr class="tr_option" rel="asm0option0"
td class="td_check"
input id="check_asm0option0" type="checkbox" value="4dbb118ddca3244e2800003d" rel="asm0option0" name="ignore"
/td
td class="td_li"
li value="0" rel="asm0option0" test /li
/td
/tr
```

```

```

```

if using .set doesn't result in your code working the way you'd expect, then examine the source and then try using .fireEvent to fire the event that should trigger the script that needs to execute.
In this case I'd try
ie.checkbox(:id => "check_asm0option0").fireEvent('onChange')

that approach is generally a bit more organic and easier than trying to invoke the script manually
```