zerocred has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I'm trying to do a bit of website automation (on a rather heavy javascripted site) using Win32::IEAutomation and having a couple of problems.

Any pointers in the right direction would be gratefully appreciated!

1. Can't seem to use 'id:' to locate element with same name and id locator:

Using 'name:' works!
#this bit works! $ie->getFrame('name:', 'info')->getImage('id:', "selBtn2")->Click();
Using 'id:' gives:
$ie->getFrame('id:', 'info')->getImage('id:', "selBtn3")->Click(); Use of uninitialized value $id in string eq at C:/Perl/site/lib/Win32/ +IEAutomation.pm line 397. WARNING: No frame is present in the document with your specified optio +n id: info
2. I get an error while trying to access an input element within an iframe in a iframe. I don't know if it is the 'id:' not working or something else. The relevant part of the DOM looks like this (IE DOM Explorer-ish)
<HTML> #top level document <HEAD> <BODY> <IFRAME id=info> #a another iframe, not a parent of sFrame <DIV id=iframeDisp> <IFRAME id=sFrame> name=sFrame #a child of top #document <HTML> <HEAD> <BODY> <IFRAME id=accFrame> #frame within sFrame #document <HTML> Tables+Tables...more stuff <INPUT class inputFld> #name=account
The code snippet I'm trying to use looks like this:
$ie->getFrame('name:','sFrame')->getFrame('id:', 'accFrame')->getTextB +ox('name:', "account")->SetValue($user)
Using 'id:' to locate sFrame doesn't seem to work either as mentioned above.
The errors produced are:
Use of uninitialized value $name in string eq at C:/Perl/site/lib/Win3 +2/IEAutomation.pm line 405. Use of uninitialized value $id in string eq at C:/Perl/site/lib/Win32/ +IEAutomation.pm line 397. Use of uninitialized value $id in string eq at C:/Perl/site/lib/Win32/ +IEAutomation.pm line 397. Use of uninitialized value $id in string eq at C:/Perl/site/lib/Win32/ +IEAutomation.pm line 397. Use of uninitialized value $id in string eq at C:/Perl/site/lib/Win32/ +IEAutomation.pm line 397. Use of uninitialized value $id in string eq at C:/Perl/site/lib/Win32/ +IEAutomation.pm line 397. WARNING: No frame is present in the document with your specified optio +n id: accFrame Can't call method "getTextBox" without a package or object reference a +t D:\dev\ieautomate\ieauto1.pl line 42.
This produces no error:
$ie->getFrame('name:', 'sFrame');
This produces unitialized $id error:
$ie->getFrame('name:', 'sFrame')->getFrame('id:','accFrame');
Use of uninitialized value $id in string eq at C:/Perl/site/lib/Win32/ +IEAutomation.pm line 397. Use of uninitialized value $id in string eq at C:/Perl/site/lib/Win32/ +IEAutomation.pm line 397. Use of uninitialized value $id in string eq at C:/Perl/site/lib/Win32/ +IEAutomation.pm line 397. Use of uninitialized value $id in string eq at C:/Perl/site/lib/Win32/ +IEAutomation.pm line 397. Use of uninitialized value $id in string eq at C:/Perl/site/lib/Win32/ +IEAutomation.pm line 397. WARNING: No frame is present in the document with your specified optio +n id: accFrame

I don't know why the error lines are repeated.

Could it be the DIV elements in between the IFRAMEs need to be navigated? - if so, how to navigate?

I tried Selenium and got it working but would run into intermittent 'cannot find element' errors while trying to locate elements inside frames, this defeated me. It was rather slow too taking about 2s per click -so that's why I'm trying IEAutomation.

Comments and suggestions welcome!

Replies are listed 'Best First'.
Re: How to use IEAutomation with iframes?
by ww (Archbishop) on Mar 11, 2010 at 15:48 UTC

    Though I can't cite a reference, offhand, and thus am uncertain that my recall is accurate, I believe I discovered some years ago that some authorities deprecate use of id="xyz" as the sole ident in an html tag "attribute=value" pair. The rationale, IIRC, is that some tools fail to parse it correctly (perhaps, ??, because of a conflict with use of id in css??

    In any case, I have utilized the proposed cure -- namely, adding name="xyz" (where xyz is identical to the value in the id="xyz") -- and that has consistently worked, over multiple sites, browsers, versions and hosts.

    I conceed, this may be OT or even irrelevant, but your statement

    Using 'name:' works!
    $ie->getFrame('name:', 'info')->getImage('id:', "selBtn2")->Click();

    leads me to suspect you control the website content and could thus make the necessary changes... perhaps even fairly painlessly.

      Hi,

      Thanks, I used CSS in Selenium and that worked OK - except for the intermittent cannot find element error (which is something to do with frames too I believe), but IEAutomation doesn't seem to support the use of CSS.

      It just so happens the first frame sFrame has both an 'id' and 'name' attribute that are both the same. Using the 'name' to locate the frame seems to work, using id does not - it led me to wonder was there a bug in the IEAutomation code - I looked at the source but the id and name functions looked so similar. The second child frame only has an 'id' so I can't avoid using it.

      Using 'id' for the image element seems to work ok.

      I don't control the site unfortunately so can't make the changes.

      So I'm a bit stuck.

        Following up on the id & name locators, I found this on w3.org site:

        "12.2.3 Anchors with the id attribute
        ...
        The id and name attributes share the same name space. This means that they cannot both define an anchor with the same name in the same document. It is permissible to use both attributes to specify an element's unique identifier for the following elements: A, APPLET, FORM, FRAME, IFRAME, IMG, and MAP. When both attributes are used on a single element, their values must be identical."

        I tried using 'name:' instead of 'id:' and it fails if there is no name attribute. So they don't seem interchangeable.