mshtml.IHTMLDocument returning nothing - vb.net

I have the below code trying to access a webpage and the program is erroring out at a test for the innerHTML property. Below is the code:
iex = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
iex.visible = True
iex.navigate("https://url.aspx")
While iex.readystate <> 4 Or iex.busy
Application.DoEvents()
End While
Dim htdoc As mshtml.IHTMLDocument = iex.Document
Dim htstring As mshtml.IHTMLBodyElement = htdoc.body
If (InStr(htstring.innerHTML, "An error occured while processing your request") > 0) Then
The last line is where it gets the error. And I have determined that it gets the error because htdoc is nothing, resulting in everything else being nothing. At least, that is what I believe the issue to be.
After further troubleshooting, the below line is what is causing the error.
mshtml.IHTMLBodyElement = htdoc.body
The exception error is:
Message = Exception from HRESULT: 0x800A01B6
Item = In order to evaluate an indexed
property, the property must be qualified and the arguments must be
explicitly supplied by the user.
This was working before IE was updated to IE11 (I don't recall what version it was prior, but I would assume it was IE10).
I don't think I am doing anything wrong, but any help you could provide would be greatly beneficial!

Related

Run time error '424' Object Required in Selenium VBA for Edge Browser

On executing below code, system throws error
Run Time Error '424'
Object Required
Through the code, I am extracting data from a website (using Edge browser).
If match is found, a link appears on the portal from which data can be downloaded whose Xpath is "//*[#id='downloadReport']/div"
If link is present, the link should be clicked using code
Obj.FindElementByXPath("//*[#id='downloadReport']/div").Click
Else if no match is found, the above code should be skipped as Xpath as above is not available and another macro execution should be called using
Call EdgeAutoTest2
I am new to coding
Please help me in resolving this error.
Sub EdgeAutoTest1()
Set Obj = New selenium.EdgeDriver
Obj.SetCapability "ms:edgeOptions", "{""excludeSwitches"":[""enable-automation""]}"
Obj.Start "edge", ""
Obj.Get "https://***website*****"
Obj.Window.Maximize
Obj.FindElementByName("croreAccount").SendKeys ("Search")
Obj.FindElementByXPath("//*[#id='loadSuitFiledDataSearchAction']/div[1]/div[3]/div[4]/img").Click
Obj.FindElementById("borrowerName").SendKeys (ThisWorkbook.Sheets("Sheet1").Range("C5").Value)
Obj.FindElementByXPath("//*[#id='search-button']/ul/li[1]/div/input").Click
Obj.Wait 20000
Obj.FindElementByXPath("//*[#id='three-icons']/ul/li[3]/a/div").Click
Obj.Wait 20000
If Obj.IsElementPresent(By.XPath("//*[#id='downloadReport']/div")) = True Then **'error occurs here*****
Obj.FindElementByXPath("//*[#id='downloadReport']/div").Click
Else
Obj.Wait 100
End If
Call EdgeAutoTest2
End Sub
The only issue in your code is you are missing is that you didn't define By.
As you are using:
If Obj.IsElementPresent(By.XPath("//*[#id='downloadReport']/div")) = True Then
You need to:
Dim By As New Selenium.By

Checking if element exists VBA Selenium

Looking for help on how to implement VBA code to check if an element exists or explicitly waiting for it in VBA. Here is a small sample code I am testing out. The below code gives an error while running since it says "Object Required"
Dim Driver As New ChromeDriver
Driver.get "Test website"
If Driver.IsElementPresent(By.XPath("/html/body/div[2]/div/div[5]/h3"))) Then
Debug.Print("Yes")
Else
Debug.Print("No")
I even have tried changing the .IsElementPresent to this line of code so I can test the size of the element if it exists but receiving an error that "NoSuchElementError"
Debug.Print (browser.FindElementByXPath("/html/body/div[2]/div/div[5]/h3").Size())
Seem to work for me. The only issue I am seeing in your code is that you didn't declare By anywhere.
e.Start isn't a requirement, but I do it anyway.
So I would try declaring By and see what happen there. And you need to set it as a new instance, a simply type-declaration won't work, which means:
Just using Dim By As Selenium.By is NOT enough, but either of these lines:
Dim By As New Selenium.By
or
Dim By As Selenium.By
Set By = New Selenium.By
The Object Required error you are receiving is likely due to the missing declaration I stated above.
As text above, for me it worked like this...
Dim ch As Selenium.ChromeDriver
Set ch = New Selenium.ChromeDriver
'... all code ...
If ch.IsElementPresent(FindBy.XPath("//*[#id='div_footer']/table/tbody/tr/div")) Then
ch.FindElement(FindBy.XPath("//*[#id='div_footer']/table/tbody/tr/div")).Click
ElseIf ch.IsElementPresent(FindBy.XPath("//*[#id='xlsbutton']")) Then
ch.FindElement(FindBy.XPath("//*[#id='xlsbutton']")).Click
Else
'nohing here, only to understand stament
boolean_check_Download_Click_XYZ = false
End If

Error getting an instance of Rumba+ in VB --AUTOMATION ERROR INVALID SYNTAX

Microfocus placed this as an example to connect to an existing Rumba (Mainframe Emulator) instance, but it is failing at the moment I try to get the object.
Sub UseExistingRumbaSession()
Dim App As RumbaApplicationObject
Dim Emul As RumbaEmulationSessionObject
RumbaDescriptors = RunningRumbaObjectDescriptors
If Len(Join(RumbaDescriptors)) > 0 Then
Set App = GetObject(RumbaDescriptors(LBound(RumbaDescriptors)))
Set Emul = App.GetSession(App.ActiveSessionID)
End If
End Sub
I get the error in this line GetObject(RumbaDescriptors(LBound(RumbaDescriptors)))
--RUN-TIME ERROR -2147221020 (800401e4) AUTOMATION ERROR INVALID SYNTAX
I also tried to do this since that is the string it returns:
GetObject("objref:TUVPVwEAAAAAAAAAAAAAAMAAAAAAAABGgQIAAAAAAAByLuk3Pl6UH86EhdmPD2aaAyAAAPA6//+efWIggTnfNjkAIAAHAFUAUwBNAEkAVwBMAEEAUAAwADUAMAA2ADcANwAAAAcAMQA3ADIALgAyADAALgAyADcALgAyADEAMQAAAAAACQD//wAAHgD//wAAEAD//wAACgD//wAAFgD//wAAHwD//wAADgD//wAAUgD//wAAAAA=:")
Can anyone help me?

Setting AutoCAD ActiveSpace to ModelSpace VB.NET

I am trying to ensure that I am addressing entities in ModelSpace, but I get an exception that gives no hint at what the problem is because it's a COM object I guess. Does anyone know what I might be doing wrong? If I take out that line (and the zoom extents line) the remaining code works just fine, so I know my document object is being set correctly.
Dim acDWG As AutoCAD.AcadDocument
' open the drawing
acDWG = acApp.Documents.Open(dgvr.Cells("FullName").Value.ToString)
' ensure the drawing has the modelspace tab activated (doesnt work)
acDWG.ActiveSpace = AutoCAD.AcActiveSpace.acModelSpace
' zoom to extents (sometimes works, sometimes not) '
acApp.ZoomExtents()
' build a selectionset of all blocks named 'Solid1' and then delete them all
Dim ss As AutoCAD.AcadSelectionSet = acDWG.SelectionSets.Add("DELETE")
Dim gpCode(1) As Int16
Dim dataValue(1) As Object
gpCode(0) = 0 : dataValue(0) = "Insert"
gpCode(1) = 2 : dataValue(1) = "Solid1"
ss.Select(AutoCAD.AcSelect.acSelectionSetAll,,, gpCode, dataValue)
ss.Erase()
ss.Delete()
ss = Nothing
Update: I discovered why I am getting the error. The code is correct, but the problem is that the drawing has not completed opening yet. If I put a "wait for 5 seconds" line of code directly after the Open line, it works just fine. So it seems my question is how to open the drawing and have VB.Net wait for a signal from the COM object that it is "ready to continue"? (not sure how to word it)
Use a combination of Do...Loop and a Try...Catch block to "wait" like this:
Dim acDWG As AutoCAD.AcadDocument
acDWG = acApp.Documents.Open(dgvr.Cells("FullName").Value.ToString)
Dim bOpen As Boolean = False
Do Until bOpen = True
Try
acDWG.ActiveSpace = AutoCAD.AcActiveSpace.acModelSpace
bOpen = True
Catch ex As Exception
' ignore the error and try again until it is open
End Try
Loop

system.NullReferenceException: Object not set to an instance of an object

Dim Permission As String
Dim chk As String = "p"
Permission = (ds.Tables("privilege").Rows(0).Item(0)).ToString
MessageBox.Show(Permission)
Dim PermissionArray() As String = Split(Permission, ":")
For i As Integer = 0 To 36
If PermissionArray(i) = 1 Then
Try
Dim chkBox As CheckBox = CType(Me.Controls(chk & i), CheckBox)
chkBox.Checked = True
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End If
Next
This code gives me the following error in catch, i have googled but nothing is working
This is the error: System.NullReferenceException – Object reference not set to an instance of an object.
As you noted chkBox.Checked throws NullReferenceException, you should evaluate the following line for the error:
Dim chkBox As CheckBox = CType(Me.Controls(chk & i), CheckBox)
' This may throw NullReferenceException if there is no (chk & i) control available
chkBox.Checked = True
Although it turned out not to be your problem this time,
Permission = (ds.Tables("privilege").Rows(0).Item(0)).ToString
is a prime candidate for a system.NullReferenceException. This statement relies on everything in your data set being fully and correctly populated or errors can occur.
If the table "privilege" does not exist in the dataset, or the table is empty, or the first column of the first row is null, you can get exceptions and it will be very hard to tell what is wrong. You should test those conditions before relying on the assignment, so you don't get exceptions.
I'll bet you are missing one or more controls "p0" ... "p35" since blindly build the ID, ask the form for the control of that ID but never check if it was actually found. Try including the value of 'i' in your message when the exception is caught. That'll be the first control you're misisng.
And then, be sure to check the return values of functions you call before you USE those return values.