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
CodePudding user response:
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