Automation with WebView

Post

Posted
Rating:
#1 (In Topic #1310)
Avatar
Trainee
ninalanyon is in the usergroup ‘Trainee’
 Does anyone have any information about automating interactions with websites using WebView?

I would like to log in to a web site automatically, to push buttons under program control, etc.

Also how does WebView handle cookies?
Online now: No Back to the top

Post

Posted
Rating:
#2
Banned
 It all depends on the webpage you are trying to automate.

Usually it's done using JavaScript

WebView.ExecJavascript() method.
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Trainee
ninalanyon is in the usergroup ‘Trainee’
I'm playing with the Corlomo CBrowser example project.  The Webview control doesn't have an ExecJavascript method.

This page says it does have it: /comp/gb.qt5.webview/webview - Gambas Documentation

Any idea what have I done wrong?
Online now: No Back to the top

Post

Posted
Rating:
#4
Banned
No idea at all. I cannot see your code
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Trainee
ninalanyon is in the usergroup ‘Trainee’
The code is just

Code (gambas)

  1. Sub x()
  2.   Try WebView1.ExecJavascript("abc")
  3.     Print Error.Code
  4.     Print Error.Text  
  5.  

When it is called I get this output
11
Unknown symbol 'ExecJavascript' in class 'WebView'
Online now: No Back to the top

Post

Posted
Rating:
#6
Banned
it works fine here.

My guess would be that you are not using gb.gui.webview but using the old gb.qt.webkit

gb.qt.webkit (that was QT only) is now depreciated so you should use gb.gui.webview (QT and GTK) instead

/comp-deprecated - Gambas Documentation   : do not use these ones
/comp - Gambas Documentation  : use these.


Ps. your code could be showing an old error (Error.code and Error.text may be filled from a previous error not the last Try)
You should do it like this…

Code (gambas)

  1.  
  2. Sub x()
  3.   Try WebView1.ExecJavascript("abc")
  4.     If Error Then
  5.       Print Error.Code
  6.       Print Error.Text  
  7.     Endif
  8.  
  9.  

I get this result..

-1
Javascript error: undefined:1:4: ReferenceError: Can't find variable: abc

And that's correct as "abc" is invalid javascript
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Trainee
ninalanyon is in the usergroup ‘Trainee’
 Perfect  Now I get the error you expected.  And i understand a bit more about how Gambas works.
Thank you very much.
Online now: No Back to the top

Post

Posted
Rating:
#8
Regular
vuott is in the usergroup ‘Regular’
By using QT6, I obtain in console:

Path override failed for key base::DIR_APP_DICTIONARIES and path '/usr/bin/qtwebengine_dictionaries'
Path override failed for key base::DIR_APP_DICTIONARIES and path '/usr/lib/qt6/qtwebengine_dictionaries'
Path override failed for key base::DIR_APP_DICTIONARIES and path '/usr/lib/qt6/qtwebengine_dictionaries'
js: Uncaught ReferenceError: abc is not defined

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#9
Banned

vuott said

By using QT6, I obtain in console:

Path override failed for key base::DIR_APP_DICTIONARIES and path '/usr/bin/qtwebengine_dictionaries'
Path override failed for key base::DIR_APP_DICTIONARIES and path '/usr/lib/qt6/qtwebengine_dictionaries'
Path override failed for key base::DIR_APP_DICTIONARIES and path '/usr/lib/qt6/qtwebengine_dictionaries'
js: Uncaught ReferenceError: abc is not defined

ooh your qt6 doesn't seem too happy.  looks like spell checker config issue.
Online now: No Back to the top

Post

Posted
Rating:
#10
Regular
vuott is in the usergroup ‘Regular’

BruceSteers said

ooh your qt6 doesn't seem too happy.
Hi BruceSteers,
…evidently my QT6 has not yet learnt that life can be bitter !  :lol:

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top
1 guest and 0 members have just viewed this.