easy ie automate

2025-12-10 0 780

EasyIEAutomate (object)

An automation wrapper class around the InternetExplorer object that makes it easy to control with VBScript.

SETUP |
USAGE |
IE-OBJECT |
PROPERTIES |
METHODS |
HISTORY |
CONTACT

Setup

First, let\’s add the class to our own VBScript file.

1. Internet connection available.

 With CreateObject(\"Msxml2.XMLHttp.6.0\")
   Call .open(\"GET\", \"https://raw.githubu*se**rcontent.com/simply-coded/easy-ie-automate/master/eiea.vbs\", False)
   Call .send() : Call Execute(.responseText)
 End With


 \'your code here...

2. No/Unwanted reliance for an internet connection.

  • Download the eiea.vbs file.

  • You can copy & paste or import the code into your VBScript file.

    • Copy & Paste
    Class EasyIEAutomate 
      \'paste the EasyIEAutomate class in place of this one.
    End Class
    
    
    \'your code here...
    • Import
    Dim eieaPath : eieaPath = \"c:\\path\\to\\eiea.vbs\"
    Execute(CreateObject(\"Scripting.FileSystemObject\").OpenTextFile(eieaPath, 1).ReadAll)    
    
    
    \'your code here...

SETUP |
USAGE |
IE-OBJECT |
PROPERTIES |
METHODS |
HISTORY |
CONTACT

Usage

Now that we\’ve added the class to our VBScript file, let\’s create an instance of it.

Initialization

Set eIE = New EasyIEAutomate

\'your code here

By default this will not create an IE process immediately. The reason for this is so that if you have an existing IE window or tab open you can grab that process instead of creating a new one. Creating or getting an existing window can be achieved in a few ways: Init(), ReBase(), RePoint(), and Latest().

Let\’s see some examples:

  • Create new with Init().
\' These all do the same thing.
\'1.
Set eIE = (New EasyIEAutomate)(vbUseDefault) 

\'2.
Set eIE = (New EasyIEAutomate)(CreateObject(\"InternetExplorer.Application\"))

\'3.
Set eIE = New EasyIEAutomate
eIE(vbUseDefault)

\'4.
Set eIE = New EasyIEAutomate
eIE(CreateObject(\"InternetExplorer.Application\"))
  • Get existing with Init().
\'Already have the object
Set objIE = CreateObject(\"InternetExplorer.Application\")
Set eIE = (New EasyIEAutomate)(objIE)
  • Get existing with ReBase().
\'Already have the object
Set objIE = CreateObject(\"InternetExplorer.Application\")
Set eIE = New EasyIEAutomate
eIE.ReBase objIE

The method ReBase() can be used at anytime to change what IE process the class is controlling and is just an alias for the Init() method.

  • Get existing with RePoint().
Set eIE = New EasyIEAutomate 

\'URL of the IE window that is already open.
eIE.RePoint \"https://www.**g*oogle.com/?gws_rd=ssl\"
  • Get existing with Latest().
Set eIE = New EasyIEAutomate 

\'Will get the most recent IE process created.
eIE.Latest 

Auto IE Initialization

If you start off with no IE process EasyIEAutomate will automatically create one when you start using the class. A one (1) second Popup of \”Auto initialized a new IE object.\” will let you know if it does.

Set eIE = (New EasyIEAutomate)(Nothing)
\' Or just: Set eIE = New EasyIEAutomate 

\' This and many other methods and properties will trigger an automatic creation of an IE process if none exist.
eIE.Show 

SETUP |
USAGE |
IE-OBJECT |
PROPERTIES |
METHODS |
HISTORY |
CONTACT

IE Object

All the IE properties and methods you\’re use to can still be accessed through the Base Property.

Set IEA = (New EasyIEAutomate)(vbUseDefault)

\'Navigate to Google.
IEA.Base.Navigate \"http://www.g**o*ogle.com/\"

\'Adjust the look of the window.
IEA.Base.AddressBar = False
IEA.Base.MenuBar = False
IEA.Base.StatusBar = False
IEA.Base.Height = 500
IEA.Base.Width = 800

\'Wait for window to load
While IEA.Base.Busy : WScript.Sleep(400) : Wend

\'Center the window on screen.
Dim SCR : Set SCR = IEA.Base.Document.ParentWindow.screen
IEA.Base.Left = (SCR.width - IEA.Base.Width) / 2
IEA.Base.Top = (SCR.height - IEA.Base.Height) / 2

\'Show the window
IEA.Base.Visible = True

\'Change the title of the window
IEA.Base.Document.title = \"Google Searcher\"

If all of this looks unfamiliar to you then I would recommend checking out all the main properties and methods here.

SETUP |
USAGE |
IE-OBJECT |
PROPERTIES |
METHODS |
HISTORY |
CONTACT

Properties

Now let\’s get into some of the new properties added.

eIE.Avail

@return
[array] – An array of available IE processes (windows and tabs).

\' EXAMPLE 1:
Set eIE = New EasyIEAutomate

\' Get number of tabs/windows opened.
count = UBound(eIE.Avail) + 1

\' Collect their names & url and show them.
collect = \"\"
For Each ie In eIE.Avail
  collect = collect & ie.LocationName & \" - \" & ie.LocationURL & vbLF  
Next

MsgBox collect, vbOKOnly, \"IE object(s) open = \" & count
\' EXAMPLE 2
Set google = New EasyIEAutomate

\' Search for a tab/window using google
For Each ie In google.Avail
  If InStr(ie.LocationURL, \"google.com/\") Then
    google(ie)
    Exit For
  End If
Next

If google.Base Is Nothing Then
  ans = MsgBox(\"IE with google was not found. Create one?\", vbYesNo + vbQuestion)
  If ans = vbYes Then        
    google(vbUseDefault) \' This creates a new IE process
    google.Base.Navigate \"https://www.goog***le.com/\"    
  Else
    WScript.Quit
  End If
End If

\' Show the window if it was hidden or a new one was created.
google.Base.Visible = True

\' Wait for it to load before trying to mess with it
While google.Base.Busy : WScript.Sleep 400 : Wend
    
\' Search for something in google.
google.Base.Document.getElementById(\"lst-ib\").Value = \"searching in google\"
google.Base.Document.getElementById(\"tsf\").Submit

WScript.Sleep 2000

\' This would be a better way to search, but these are just examples.
google.Base.Navigate \"https://www.goog***le.com/#q=alternative+search+in+google\"

eIE.Base

@return
[object] – The main Internet Explorer object. See IE object.

eIE.Url

@return
[string] – The URL of the current IE process. Same as eIE.Base.LocationURL. Alerts if no IE process exists.

eIE.Title

@return
[string] – The title of the current IE process. Same as eIE.Base.LocationName. Alerts if no IE process exists.

SETUP |
USAGE |
IE-OBJECT |
PROPERTIES |
METHODS |
HISTORY |
CONTACT

Methods

eIE.Close( )

Closes the current IE process. Same as eIE.Base.Quit. Alerts if no IE process exists.

eIE.CloseAll( )

Closes all open IE processes (hidden or visible).

eIE.Show( )

Sets the visiblilty of the current IE process to true. Same as eIE.Base.Visible = True. Alerts if no IE process exists, and then creates one.

eIE.Hide( )

Sets the visiblilty of the current IE process to false. Same as eIE.Base.Visible = False. Alerts if no IE process exists, and then creates one.

eIE.Center( )

Centers the window on screen. If no website is loaded one with \”about:blank\” will be navigated to. A loaded website is necessary to get the screen resolution.

Set eIE = (New EasyIEAutomate)(vbUseDefault)

\' Centering before the browser is visible makes for a nicer looking experience.
eIE.Center
eIE.Show

eIE.Navigate( url )

Navigates the IE process to this location. Same as eIE.Base.Navigate2 \”URL_HERE\”. Alerts if no IE process exists, and then creates one.
@params
url [string] – An address url to navigate to.

eIE.NavigateTab( url )

Creates a new tab and navigates the IE process to this location. Same as eIE.Base.Navigate2 \”URL_HERE\”, 2048. Alerts if no IE process exists, and then creates one.
@params
url [string] – An address url to navigate to.

eIE.NavigateBgTab( url )

Creates a new background tab and navigates the IE process to this location. Same as eIE.Base.Navigate2 \”URL_HERE\”, 4096. Alerts if no IE process exists, and then creates one.
@params
url [string] – An address url to navigate to.

eIE.WaitForLoad( )

Waits for the current IE process to finish loading. Alerts if no IE process exists.

eIE.DeepWaitForLoad( elem )

The method waits for the inputed element to finish loading. The current page could be loaded but content inside of it like an iframe, could still need time to load.
@params
elem [object] – An HTML element object like an iframe.

Set eIE = (New EasyIEAutomate)(vbUseDefault)

eIE.Navigate \"https://rawgit*.*co*m/simply-coded/easy-ie-automate/master/practice/index.html\"
eIE.Show

\' Wait for main webpage to load
eIE.WaitForLoad

\' Get an iframe on that page. 
Set myFrame = eIE.Base.Document.getElementById(\"ice_frame\")

\' Wait for iframe to load if it hasn\'t already.
eIE.DeepWaitForLoad(myFrame)

\' To access things inside an iframe it must respect the same origin policy!
MsgBox myFrame.contentDocument.querySelector(\"img\").src, vbOKOnly, \"The image source is:\"

There\’s an easier way however. The next example does the same thing as this one by using a function called Deeper().

eIE.Deeper( squery )

Method waits for element to load and then returns the frame\’s contentDocument. Alerts and quits the script if same origin policy is violated. Used for accessing/editing things within a frame.
@params
squery [string] – A query string to get the iframe.
@return
[object] – The frame element\’s contentDocument as an object.

Set eIE = (New EasyIEAutomate)(vbUseDefault)

eIE.Navigate \"https://rawgit*.*co*m/simply-coded/easy-ie-automate/master/practice/index.html\"
eIE.Show

\' Waits for main webpage to load, selects the element, waits for it to load, 
\' and then returns the element\'s contentDocument. Alerts and quits if same 
\' origin policy is violated.
Set myFrame = eIE.Deeper(\"#ice_frame\")
MsgBox myFrame.querySelector(\"img\").src, vbOKOnly, \"The image source is:\"

eIE.ReBase( ie )

Changes the Base to a different Internet Explorer object. Alias for the default Init() method. An example can be found in the usage section.
@params
ie [object] – The Internet Explorer window/tab object you want to change the Base object to.

eIE.RePoint( url )

Changes the Base to a different Internet Explorer object. An example can be found in the usage section.
@params
url [string] – An url of an Internet Explorer window/tab that is currently opened that you want to change the Base object to.

eIE.Latest( )

Changes the Base to the most recent Internet Explorer object. An example can be found in the usage section.

eIE.Query( squery )

Uses eIE.Base.Document.querySelector( squery ) to retrieve an element. Here is documentation on Element.querySelector(). Here are the various ways to search for elements. Waits for document to load before searching, and alerts and quits if it cannot be found.
@params
squery [string] – The query string to select the element with.
@return
[object] – The found element as an object.

Set eIE = (New EasyIEAutomate)(vbUseDefault)

eIE.Navigate \"https://rawgit*.*co*m/simply-coded/easy-ie-automate/master/practice/index.html\"
eIE.Show

\' get various elements and interact with them
eIE.Query(\".titles\").style.color = \"deepskyblue\"
eIE.Query(\"input[name=\'email\']\").Value = \"simplycoded.help@gmail.com\"
eIE.Query(\"#pass\").Value = \"bananas_are_the_universal_scale\"
eIE.Query(\"#milk\").removeAttribute(\"checked\")
eIE.Query(\"input[type=\'radio\'][value=\'female\']\").setAttribute(\"checked\")
eIE.Query(\"form > p > button\").Click

eIE.QueryAll( squery )

Uses eIE.Base.Document.querySelectorAll( squery ) to retrieve a NodeList. Here are the various ways to search for elements. Waits for document to load before searching, and alerts and quits if something cannot be found.
@params
squery [string] – The query string to select the elements with.
@return
[object] – The found elements as a NodeList object.

Set eIE = (New EasyIEAutomate)(vbUseDefault)
eIE.Navigate \"https://rawgit*.*co*m/simply-coded/easy-ie-automate/master/practice/index.html\"
eIE.Show

\' get elements with class=\"titles\" and all <p> tag elements
Set list = eIE.QueryAll(\".titles, p\")

\' change their style up a bit
For i = 0 To list.length - 1
  list.item(i).style.backgroundColor = \"white\"  
  list.item(i).style.border = \"2px solid deepskyblue\"  
  list.item(i).style.fontFamily = \"Consolas, monospace\"
Next

SETUP |
USAGE |
IE-OBJECT |
PROPERTIES |
METHODS |
HISTORY |
CONTACT

History

  • 1.1
    • ADD – Documentation added to README.md.
    • CHANGE – Methods renamed as follows: NavigateT() to NavigateTab(), and NavigateBT() to NavigateBgTab().
    • CHANGEReBase() now an alias for Default Init() method.
    • ADD – Timed popups for errors not worth quitting over. See documentation for what methods alert.
    • CHANGE – Practice folder examples have changed in challenge.vbs and answers.vbs to reflect newest syntax.
  • 1.0
    • ADD – Initial release.

SETUP |
USAGE |
IE-OBJECT |
PROPERTIES |
METHODS |
HISTORY |
CONTACT

Meta

Jeremy England ( SimplyCoded ) – simplycoded.help@gmail.com

Distributed under the MIT license. See LICENSE for more information.

下载源码

通过命令行克隆项目:

git clone https://github.com/simply-coded/easy-ie-automate.git

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

申明:本文由第三方发布,内容仅代表作者观点,与本网站无关。对本文以及其中全部或者部分内容的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。本网发布或转载文章出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,也不代表本网对其真实性负责。

左子网 编程相关 easy ie automate https://www.zuozi.net/33316.html

LoRA
上一篇: LoRA
常见问题
  • 1、自动:拍下后,点击(下载)链接即可下载;2、手动:拍下后,联系卖家发放即可或者联系官方找开发者发货。
查看详情
  • 1、源码默认交易周期:手动发货商品为1-3天,并且用户付款金额将会进入平台担保直到交易完成或者3-7天即可发放,如遇纠纷无限期延长收款金额直至纠纷解决或者退款!;
查看详情
  • 1、描述:源码描述(含标题)与实际源码不一致的(例:货不对板); 2、演示:有演示站时,与实际源码小于95%一致的(但描述中有”不保证完全一样、有变化的可能性”类似显著声明的除外); 3、发货:不发货可无理由退款; 4、安装:免费提供安装服务的源码但卖家不履行的; 5、收费:价格虚标,额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外); 6、其他:如质量方面的硬性常规问题BUG等。 注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。
查看详情
  • 1、左子会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全! 2、左子无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别; 3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外); 4、在没有”无任何正当退款依据”的前提下,商品写有”一旦售出,概不支持退款”等类似的声明,视为无效声明; 5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准); 6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在左子上所留的QQ、手机号沟通,以防对方不承认自我承诺。 7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于左子介入快速处理。
查看详情

相关文章

猜你喜欢
发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务