B4J Library [b4j] jSelenium 2.0.1 - A Test Automation for B4J

This is my very first attempt to create a wrap for a library, It is based on this project:
- https://www.selenium.dev/downloads/
jSelenium - version 1.0

Usage​

* Third party Jar:

AdditionalJar:
#AdditionalJar: client-combined-3.14.0.jar
#AdditionalJar: animal-sniffer-annotations-1.14.jar
#AdditionalJar: byte-buddy-1.8.15.jar
#AdditionalJar: checker-compat-qual-2.0.0.jar
#AdditionalJar: commons-codec-1.10.jar
#AdditionalJar: commons-exec-1.3.jar
#AdditionalJar: commons-logging-1.2.jar
#AdditionalJar: error_prone_annotations-2.1.3.jar
#AdditionalJar: guava-31.1-jre.jar
#AdditionalJar: httpclient-4.5.5.jar
#AdditionalJar: httpcore-4.4.9.jar
#AdditionalJar: j2objc-annotations-1.1.jar
#AdditionalJar: okhttp-3.10.0.jar
#AdditionalJar: jsr305-1.3.9.jar
#AdditionalJar: selenium-api-4.3.0.jar
#AdditionalJar: selenium-chromium-driver-4.3.0.jar
#AdditionalJar: selenium-java-3.14.0.jar
#AdditionalJar: selenium-support-4.3.0.jar
#AdditionalJar: selenium-remote-driver-4.3.0.jar
#AdditionalJar: okio-1.14.1.jar
#AdditionalJar: opentelemetry-sdk-1.16.0.jar
#AdditionalJar: opentelemetry-sdk-extension-autoconfigure-spi-1.16.0.jar

Using:
ClassName
id
CssSelector
Xpath
LinkText
Name
Partiallinktext
Tagname        

Example:
jChrome.SelecElement("//a[contains(text(),'B4J - Desktop, Server and Raspberry Pi')]", "xpath")

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    jChrome.Initialize("jChrome", "D:\B4J\b4jSelenium\jSelenium\Driver", "chromedriver104.exe")
    jChrome.Create
End Sub

Sub Button1_Click  
    'jChrome.HideAutomation(True)
    jChrome.loadURL("https://www.showmyip.com/")
    Sleep(1000)
    jChrome.ReadCookies(File.DirApp, "fb.cookies")
    Sleep(500)
    jChrome.Refresh
End Sub

EVENTS

Events:
Sub jChrome_PageFinished (error As String, success As Boolean)
    Log("PageFinished:" & success)
End Sub
Sub jChrome_AfterClickOn ()
    Log("AfterClickOn")
End Sub
Sub jChrome_BeforeClickOn()
    Log("BeforeClickOn")
End Sub

Sub jChrome_BeforeAlertAccept()
    Log("BeforeAlertAccept")
End Sub
   
Sub jChrome_AfterAlertAccept()
    Log("AfterAlertAccept")
End Sub

Sub jChrome_BeforeAlertDismiss()
    Log("BeforeAlertDismiss")
End Sub
Sub jChrome_AfterAlertDismiss()
    Log("AfterAlertDismiss")
End Sub
   
Sub jChrome_AfterNavigateTo(url As String)
    Log(url)
End Sub
Sub jChrome_BeforeNavigateTo(url As String)
    Log(url)
End Sub
Sub jChrome_AfterNavigateBack(url As String)
    Log(url)
End Sub
Sub jChrome_BeforeNavigateBack(url As String)
    Log(url)
End Sub
Sub jChrome_BeforeNavigateForward(url As String)
    Log(url)
End Sub
Sub jChrome_AfterNavigateForward(url As String)
    Log(url)
End Sub
Sub jChrome_AfterNavigateRefresh(url As String)
    Log(url)
End Sub
Sub jChrome_BeforeNavigateRefresh(url As String)
    Log(url)
End Sub
Sub jChrome_AfterFindBy()
    Log("AfterFindBy")
End Sub
Sub jChrome_BeforeFindBy()
    Log("BeforeFindBy")
End Sub

Sub jChrome_AfterChangeValueOf(keysToSend As String)
    Log("AfterChangeValueOf")
End Sub

Sub jChrome_BeforeChangeValueOf(keysToSend As String)
    Log("BeforeChangeValueOf")
End Sub
Sub jChrome_BeforeScript(script As String)
    Log("BeforeScript")
End Sub

Sub jChrome_AfterScript(script As String)
    Log("AfterScript")
End Sub

Sub jChrome_BeforeSwitchToWindow(windowName As String)
    Log(windowName)
End Sub

Sub jChrome_AfterSwitchToWindow(windowName As String)
    Log(windowName)
End Sub

Sub jChrome_OnException(throwable As String)
    Log(throwable)
End Sub

Sub jChrome_BeforeGetScreenshotAs()
    Log("BeforeGetScreenshotAs")
End Sub

Sub jChrome_AfterGetScreenshotAs()
    Log("AfterGetScreenshotAs")
End Sub

Sub jChrome_BeforeGetText(value As String)
    Log("BeforeGetText")
End Sub

Sub jChrome_AfterGetText(value As String)
    Log("AfterGetText")
End Sub

Download: https://github.com/tummosoft/jSelenium/releases/tag/Selenium
 

Attachments

  • jSelenium-2.0.1.zip
    15.8 KB · Views: 158
Last edited:

tummosoft

Member
Licensed User
Longtime User
Thank you it works, and how to scroll the window, current i work with scrap data from google maps any idea scroll window to bottom/end of data


Thanks

- Get the entire document height with JavaScript
B4X:
documentlength = jChrome.ExecuteAsyncScript($"
            function getDocumentHeight() {
                 return document.documentElement.scrollHeight;
            }
            var callback = arguments[arguments.length - 1];
            callback(getDocumentHeight());
    "$)

- Make a scroll step

Dim nextpoint As Int = jChrome.GetScreenHeight / 2

- Begin scroll:

B4X:
If currentpos < documentlength Then
        jChrome.Scroll(0, currentpos)
        currentpos = currentpos + nextstep
    End If
 

Attachments

  • Send Keys.zip
    20.8 KB · Views: 92

syerif

Active Member
Licensed User
Longtime User
1680236543724.png


thank you for your code it is great example,

but i still can implement it in code to scroll the result until end of data

best regards
 

tummosoft

Member
Licensed User
Longtime User
The example was attach on this reply!
(1) Get height of element:
B4X:
documentlength = jChrome.ExecuteAsyncScript($"
            function getDocumentHeight() {
                 return document.querySelector("body.LoJzbe.keynav-mode-off.screen-mode:nth-child(2) div.vasquette.id-app-container.y2iKwd.cSgCkb.xcUKcd.pane-open-mode:nth-child(7) div.id-content-container:nth-child(9) div.XltNde.tTVLSc div.w6VYqd div.bJzME.tTVLSc:nth-child(2) div.k7jAl.lJ3Kh.miFGmb > div.e07Vkf.kA9KIf:nth-child(1)").scrollHeight;
            }
            
            var callback = arguments[arguments.length - 1];
            callback(getDocumentHeight());
    "$)

(2) Auto scrool by javascript
B4X:
jChrome.ExecuteScript($"
            var pos = ${currentpos};
            document.querySelector("body.LoJzbe.keynav-mode-off.screen-mode:nth-child(2) div.vasquette.id-app-container.y2iKwd.cSgCkb.xcUKcd.pane-open-mode:nth-child(7) div.id-content-container:nth-child(9) div.XltNde.tTVLSc div.w6VYqd div.bJzME.tTVLSc:nth-child(2) div.k7jAl.lJ3Kh.miFGmb > div.e07Vkf.kA9KIf:nth-child(1)").scrollTo(0,pos);
            
        "$)


 

Attachments

  • Send Keys.zip
    28.6 KB · Views: 96

syerif

Active Member
Licensed User
Longtime User
hi,
is there any way to get list from webElement with your library?

thank you
 
Last edited:
Top