Another it works here but...

Started by stanl, August 27, 2021, 06:07:13 AM

Previous topic - Next topic

stanl

In a post a while back, the ask was about automating Edge once IE support is deprecated... had some spare time and downloaded SeleniumBasic [just google, it installs in your user appdata/local folder] and got the most recent Edge WebDriver [copied to appdata/local, deleted current edgedriver and renamed it - msedgedriver.exe => edgedriver.exe].


Then the fun part: just wanted to open a url

       
  • the basic .vbs script [I added a url ] worked


Set Assert = CreateObject("Selenium.Assert")


Class Script
    Dim driver


    Sub Class_Initialize
        Set driver = CreateObject("Selenium.EdgeDriver")
        driver.Get "https://www.automationandagile.com/p/sample-form.html"
      driver.FindElementByName("fname").Sendkeys ("Win")
        driver.FindElementByName("lname").Sendkeys ("Batch")
      driver.FindElementByXPath("*//*[@value='m']").Click
      driver.FindElementByXPath("*//*[@value='Poetry']").Click
      driver.FindElementByXPath("*//*[@value='Reading']").Click
      driver.FindElementByName("occupation").AsSelect.SelectByText ("Business")
        driver.FindElementByName("day").AsSelect.SelectByText ("25")
      driver.FindElementByName("month").AsSelect.SelectByText ("Mar")
      driver.FindElementByXpath("(//*[@name='day'])[2]").AsSelect.selectByText("1996")
        WScript.Echo "Click OK to quit."
    End Sub


    Sub Class_Terminate
        driver.Quit
    End Sub
End Class


Set s = New Script




       
  • but try to replicate in WB [fails with Invalid Class String]
Code (WINBATCH) Select


url = "https://www.automationandagile.com/p/sample-form.html"
Assert = CreateObject("Selenium.Assert")
driver = CreateObject("Selenium.EdgeDriver")
driver.Get(url)



when I downloaded the Edge WebDriver, I specified x86 which I assumed would be correct for WB CreateObject()...


any ideas.

td

A few observations:

.The bitness by itself doesn't matter. All that matters is that all the pieces have the same bitness.

Selenium.dll is a "managed" assembly with COM bindings and not a native COM Automation dll.

And no it is not about .Net 5 as the default setting for the in-process server is mscoree.dll which is part of the FCL (.Net 4.whatever.)

The attempt to install the Firefox browser extension failed miserably. Firefox reports that the extension is corrupt.

The WIL Type Viewer dutifully displays the type library with all of its interfaces, enumerations, and classes. Interestingly, none of the classes have progids and any attempt to use a Selenium progid in the Viewer's Programmatic Identifier List tab reports an object not found error.

Conclusion: Selenium does not support standard COM Automation interfaces and you could give CLR hosting a try after a little research into the availability of publicly exposed .Net classes.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Some other observations:

       
  • I have ProgId's for classes in my registry
  • Even though I have no rights at work [can't even run Regedit] the Selenium and Edge stuff works with .vbs
  • Why can VBS, AutoIt, Excel run this code [modified for application specifics] so easily
  • I don't want to start an argument. My original intent was to offer a suggestion to the OP who first started the question about browser automation with IE going down. And I didn't bring up .Net 5
  • Not a big fan of Edge, but have to deal with the cards you are given.
I did make a slight modification, so works in Powershell as COM Object


if ("Win32Functions.Win32ShowWindowAsync" -as [type]) {} else {                                                               
Add-Type –memberDefinition @'                                                                                                 
[DllImport("user32.dll")]                                                                                                     
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);                                                         
'@ -name Win32ShowWindowAsync -namespace Win32Functions                                                                       
}                                                                                                                             
#minimize window                                                                                                               
[Win32Functions.Win32ShowWindowAsync]::ShowWindowAsync((Get-Process –id $pid).MainWindowHandle, 2) 




$assert = New-Object -ComObject Selenium.Assert
$driver = New-Object -ComObject Selenium.EdgeDriver
$driver.Get("https://www.automationandagile.com/p/sample-form.html")
$driver.FindElementByName("fname").Sendkeys("Win")
$driver.FindElementByName("lname").Sendkeys("Batch")
$driver.FindElementByXPath("*//*[@value='m']").Click()
$driver.FindElementByXPath("*//*[@value='Poetry']").Click()
$driver.FindElementByXPath("*//*[@value='Reading']").Click()
$value= "Business"
$driver.FindElementByName("occupation").Sendkeys($value)
$value = "25"
$driver.FindElementByName("day").Sendkeys($value)
$value = "Mar"
$driver.FindElementByName("month").Sendkeys($value)
$value = "1996"
$driver.FindElementByXpath("(//*[@name='day'])[2]").Sendkeys($value)
$driver.FindElementById("btnSubmit").Click()




Add-Type -AssemblyName  System.Windows.Forms
$message = 'Form Has Been Filled In'
$title = 'Edge Browser Automation'

[System.Windows.Forms.MessageBox]::Show($message, $title, [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]:: Information)
$driver.Quit()

td

Yes, I know you have progids. The WIL Type Viewer told me and, hopefully, you that. I also checked the registry to make sure and that is how I knew the dll information as stated above. I can't tell you the "why" other than what was previously stated. I can tell you that VBS is part of the OS so you can't assume that it has the same implementation it had in a previous version of Windows. MSFT can make whatever changes they want and the user can be oblivious to those changes.  We will discover the why down the road but now is not the time.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

Also COM != COM Automation. The relationship is COM > COM Automation.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Quote from: td on August 27, 2021, 12:46:52 PM
Also COM != COM Automation. The relationship is COM > COM Automation.


sounds like COMmunism. NP. I was just playing around, but will be using PS for some issues at work [since it works] that involve Edge. In thinking back to the thread the OP started, Selenium was my suggestion, but there were others that may better meet the need.

td

I believe the problem has to do with the process "Integrity Level", a.k.a., UAC. I forgot to do one of the basic debugging tests which is to run a script at low integrity level. This is done by giving a script .wbt_if extension. Making this simple change allows a script to create the "Selenium.Assert" object. Apparently, the .Net based objects are using .Net security attributes even though they are exposed as COM Automation objects.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Thanks!!


Running studio as admin with _if added, worked and opening Edge was fast. Any further advice on compiling. I would probably put the CreateObject()'s in a udf and supply url and processing directions as an .ini/map setup.


[EDIT]: another good learning experience for objects and .NET
Code (WINBATCH) Select


url = "https://www.automationandagile.com/p/sample-form.html"
Assert = CreateObject("Selenium.Assert")
driver = CreateObject("Selenium.EdgeDriver")
driver.Get(url)
driver.FindElementByName("fname").Sendkeys("Win")
driver.FindElementByName("lname").Sendkeys("Batch")
driver.FindElementByXPath("*//*[@value='m']").Click()
driver.FindElementByXPath("*//*[@value='Poetry']").Click()
driver.FindElementByXPath("*//*[@value='Reading']").Click()
value= "Business"
driver.FindElementByName("occupation").Sendkeys(value)
value = "25"
driver.FindElementByName("day").Sendkeys(value)
value = "Mar"
driver.FindElementByName("month").Sendkeys(value)
value = "1996"
driver.FindElementByXpath("(//*[@name='day'])[2]").Sendkeys(value)
driver.FindElementById("btnSubmit").Click()


Message("Click To Close Edge","Form is Filled")


driver.Quit()

td

Compiling with "No UAC Info" or a combination of "asInvoker" and "false" should work. If that is what you are asking about.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Thanks again. I did do a stab from the past and we worked out Selenium with CLR and chrome driver in 2018. Think it just died there.... with a simple Google search :o


Code (WINBATCH) Select


;; mods to Tony's Original Script - adapted to Chrome
;;    Selenium.WebDriverBackedSelenium.dll
;;    WebDriver.dll
;;    WebDriver.Support.dll
;;    ChromeDriver.exe
;; Stan Littlefield, 3/22/2018
;================================================================================================
ObjectClrOption("Appbase", 'C:\Scripts\Selenium')  ; note changed path
                                           ; files just extracted from Nuget Packagaes with 7-Zip


;; Load everything to be safe...
ObjectClrOption("use", 'WebDriver')
;ObjectClrOption("use", 'WebDriver.Support')    ;can work without this
;ObjectClrOption("use", 'Selenium.WebDriverBackedSelenium')  ;can work without this
_TRUE = ObjectType( "BOOL", @TRUE )
_FALSE = ObjectType( "BOOL", @FALSE )




objBy = ObjectClrNew('OpenQA.Selenium.By')
oSvc = ObjectClrNew('OpenQA.Selenium.Chrome.ChromeDriverService')
oSvc= oSvc.CreateDefaultService()
oSvc.HideCommandPromptWindow = ObjectType( "BOOL", -1 )
oSvc.Start()


objDriver = ObjectClrNew('OpenQA.Selenium.Chrome.ChromeDriver',oSvc)




objDriver.Navigate().GoToUrl("http://www.google.com/")
   
;; Find the text input element by its name
objQuery = objDriver.FindElement(objBy.Name("q"))
   
;; Enter something to search for
objQuery.SendKeys("Cheese")


;; Now submit the form. WebDriver will find the form for us from the element
objQuery.Submit()


TimeDelay(2)
objDriver.Quit()


;; Closes opened windows.
objBy = 0
objQuery = 0
objDriver = 0
exit

td

Completely forgot about that one. I did a quick search of the WinBatch Studio ".Net" project on my notebook and low and behold.

Personal note: I am currently in Berkeley CA and I don't have access to my workstation back in Washington state for security reasons. We are celebrating my youngest daughter's doctoral dissertation presentation. She is receiving her doctorate in Molecular and Cell Biology and more specifically immunology. I am one proud papa.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Quote from: td on August 28, 2021, 09:51:55 AM
We are celebrating my youngest daughter's doctoral dissertation presentation. She is receiving her doctorate in Molecular and Cell Biology and more specifically immunology. I am one proud papa.


Congrats to her, and I know the feeling. Our daughter majored in Biology at Duke, doctorate from Emory. Could have walked next door to the CDC but chose teaching over lab work.

kdmoyers

Quote from: td on August 28, 2021, 09:51:55 AMWe are celebrating my youngest daughter's doctoral dissertation presentation. She is receiving her doctorate in Molecular and Cell Biology and more specifically immunology. I am one proud papa.
Congrats! Clearly, you did something very right.  Best of luck to her.
The mind is everything; What you think, you become.

JTaylor

Stan,

    Just wanted to say Thanks for this thread.  You have potentially solved what is quickly becoming a HUGE problem for me.    THANK YOU!!!

Jim

td

I am just surprised you all did figure this one out without my stumbling into MSFT's inconsistency in applying its own standard to COM Automation security.

At least this topic may help other forum members encountering similar problems creating COM Automation objects implemented by .Net assemblies.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

So far it has worked VERY well.   While the Help is not completely useless I am definitely spoiled by WinBatch Help.   So far I have found it easier and more efficient than IE COM on many fronts.   Sometimes hard to find the right command, even with googling though, but starting to get a feel for it.   Hope to post an example script once I get something converted that was starting to having problems with IE.

Jim


Quote from: td on September 04, 2021, 08:22:28 AM
I am just surprised you all did figure this one out without my stumbling into MSFT's inconsistency in applying its own standard to COM Automation security.

At least this topic may help other forum members encountering similar problems creating COM Automation objects implemented by .Net assemblies.