Java – how to use selenium to record test cases in IE

I'm a beginner in selenium

My application is only ie compatible

I know that we can run test cases in any browser using the corresponding driver, but can we use any method to record test cases in Internet Explorer using selenium ide?

Solution

We have implemented our own recorder, which is only used to record in Internet Explorer This is a JavaScript file

The concept is to add listeners to each object in the source code of the Web GUI The following code can help you do this These listeners are added when the page is loaded When you click, all its properties are captured

Here I give an example of adding a listener and getting the properties of an object of type "select". You can perform the same operation on other types of objects

var added_MClistener = false;     
    var tagn = dObj.tagName;    
            if(tagn == "SELECT")
                  {
                     dObj.attachEvent("onchange",so_showObjInfo);
                     dObj.added_OClistener = true;
                     dObj.so_prevBGColor = alll[i].style.backgroundColor;
                }
            if(tagn != "OPTION" && tagn != "SELECT" )
              {  
            dObj.added_MClistener = true;
             dObj.attachEvent("onclick",so_showObjInfo);
             dObj.so_prevBGColor = alll[i].style.backgroundColor;
             }
    function so_showObjInfo(e) {

    if(pause)return;
     if(isActive)return;
var preE = e;
    var e =e? e:window.event;
var ele=e.target?e.target:e.srcElement;

    activeObj = ele;
    var eltagn= activeObj.tagName;
var currentNode=activeObj;
    var path=[];
while(currentNode){var pe=getNode(currentNode);if(pe){path.push(pe);if(pe.indexOf('@id')!=-1)break;}currentNode=currentNode.parentNode;}var xpath="//"+path.reverse().join('/');
    var fff=0;
    var xpath;
    while(currentNode){var pe=getNode(currentNode);if(pe){path.push(pe);if(pe.indexOf('@id')!=-1){fff=1; break;}if(pe.indexOf('@name')!=-1){fff=1; break;}}currentNode=currentNode.parentNode;}if(fff==1){xpath="//"+path.reverse().join('/');}

   var acurrentNode=activeObj;
    var apath=[];
    while(acurrentNode){var ape=agetNode(acurrentNode);if(ape){apath.push(ape);}acurrentNode=acurrentNode.parentNode;} var axpath="//"+apath.reverse().join('/');
var el=activeObj;
     var cssPath = cssselect(el);
     if (cssPath!=null)
     {
     cssPath="css="+cssPath;
     }
     var objval=activeObj.value;
     var objname=activeObj.name;
    var objidd=activeObj.id;
}

In this way, we can add listeners to objects on Web pages and get their properties Now it's up to you to decide what to do next You can write it in Excel like us (in a specific format) or create a notepad file

I hope I can help you

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>