Automation with WebView

For questions about Gambas web tools.
Post Reply
User avatar
ninalanyon
Posts: 4
Joined: Tuesday 13th August 2024 9:28pm
Location: Norway

Automation with WebView

Post by ninalanyon »

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?
User avatar
BruceSteers
Posts: 1825
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Automation with WebView

Post by BruceSteers »

It all depends on the webpage you are trying to automate.

Usually it's done using JavaScript

WebView.ExecJavascript() method.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
ninalanyon
Posts: 4
Joined: Tuesday 13th August 2024 9:28pm
Location: Norway

Re: Automation with WebView

Post by ninalanyon »

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: https://gambaswiki.org/wiki/comp/gb.qt5.webview/webview

Any idea what have I done wrong?
User avatar
BruceSteers
Posts: 1825
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Automation with WebView

Post by BruceSteers »

No idea at all. I cannot see your code
If at first you don't succeed , try doing something differently.
BruceS
User avatar
ninalanyon
Posts: 4
Joined: Tuesday 13th August 2024 9:28pm
Location: Norway

Re: Automation with WebView

Post by ninalanyon »

The code is just

Sub x()
  Try WebView1.ExecJavascript("abc")
    Print Error.Code
    Print Error.Text  
End


When it is called I get this output
11
Unknown symbol 'ExecJavascript' in class 'WebView'
User avatar
BruceSteers
Posts: 1825
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Automation with WebView

Post by BruceSteers »

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

https://gambaswiki.org/wiki/comp-deprecated : do not use these ones
https://gambaswiki.org/wiki/comp : 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...

Sub x()
  Try WebView1.ExecJavascript("abc")
    If Error Then
      Print Error.Code
      Print Error.Text  
    Endif
End



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
If at first you don't succeed , try doing something differently.
BruceS
User avatar
ninalanyon
Posts: 4
Joined: Tuesday 13th August 2024 9:28pm
Location: Norway

Re: Automation with WebView

Post by ninalanyon »

Perfect Now I get the error you expected. And i understand a bit more about how Gambas works.
Thank you very much.
vuott
Posts: 297
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Automation with WebView

Post by vuott »

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 !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
BruceSteers
Posts: 1825
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Automation with WebView

Post by BruceSteers »

vuott wrote: Friday 16th August 2024 1:23am 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.
If at first you don't succeed , try doing something differently.
BruceS
vuott
Posts: 297
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Automation with WebView

Post by vuott »

BruceSteers wrote: Friday 16th August 2024 6:10pm 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 !

Amare memorentes atque deflentes ad mortem silenter labimur.
Post Reply