SeleniumBasic icon indicating copy to clipboard operation
SeleniumBasic copied to clipboard

Getting timeout error everytime

Open 1212pratyush opened this issue 3 years ago • 1 comments

Code Error Hi,

I am getting the attached error every time I run my code. Workflow of the page is like:

  1. I fill all the required data
  2. Select excel file
  3. 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.

1212pratyush avatar Jul 10 '21 08:07 1212pratyush

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

mogulman52 avatar Jul 17 '21 17:07 mogulman52