SeleniumBasic
SeleniumBasic copied to clipboard
Getting timeout error everytime
Hi,
I am getting the attached error every time I run my code. Workflow of the page is like:
- I fill all the required data
- Select excel file
- Click on download button
The data is very big (everyday data comes around 150 rows and there are 118 columns and generally takes 10 min to download) and I have to download it on a monthly basis. Please help me out.
I've had problems with clicking buttons on certain websites and certain browsers. I've tried numerous techniques. I create functions that have On Error GoTo Handler setting on all functions. I use XPath to find all elements. I first first find element then click on it. I also use User Defined Types to simplify variable passing.
Simple Click function
Function GetElementClick(k As bookUT) As Boolean
On Error GoTo Handler
k.text = ""
Set k.ele = drv.FindElementByXPath(k.xpath)
k.ele.Click
drv.Wait (1000)
GetElementClick = True
Exit Function
Handler:
Err.Clear
GetElementClick = False
End Function
Function finds element on page and moves mouse to middle of element then clicks mouse.
Function GetElementMouseClick(k As bookUT) As Boolean
Dim m As Mouse
Dim s As String
On Error GoTo Handler
k.text = ""
Set k.ele = drv.FindElementByXPath(k.xpath)
Set k.pt = k.ele.Location
Set k.sz = k.ele.Size
Set m = drv.Mouse '
k.width = k.sz.width / 2
k.height = k.sz.height / 2
Set m = m.MoveTo(k.ele, k.width / 2, k.height / 2)
s = "x:" & k.pt.x & " ,y:" & k.pt.y & " ,w:" & k.sz.width & " ,h:" & k.sz.height
' Debug.Print s
m.Click
GetElementMouseClick = True
Exit Function
Handler:
Err.Clear
GetElementMouseClick = False
End Function
Calling function
k.xpath = "//button[contains(text(),'Search')]"
If GetElementMouseClick(k) Then ' Edge needs mouse click
Public Type bookUT
xpath As String
ele As WebElement
eleEach As WebElement
eles As WebElements
eleSel As SelectElement
browser As String
text As String
width As Long
height As Long
x As Long
y As Long
sz As Selenium.Size
pt As Selenium.Point
emailStr As String
recordStr As String
reason As String
urlStr As String
End Type