B4J Question [pdn_selenium] page url change not detected

Cableguy

Expert
Licensed User
Longtime User
I am making good progress with my tryouts, but one thing I can't seem to get to work is that, when the page url changes due to i.e. a form submit, the "NavigationFinished" is not fired.

What I am trying to do is:
load page x+1
in NavigationFinished:
if loaded page is x (due to the need to log in, then log in : this should automatically load page x + 1 ; return to NavigationFinished
if loaded page is x+1 (loged in) I can continue

This check is something I will need to do each time a page is loaded within the x domain
 

Cableguy

Expert
Licensed User
Longtime User
This is what I came with...
B4X:
            LogInSubmitButton.Click
            Do While Selenium.CurrentUrl = ServerURL
                Sleep(0)
            Loop
            Sleep(1000)
            Selenium_NavigationFinished
it works for now, but I wonder if page reload and url changes shouldn't be automatically detected (?)
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
Documents for .Click
B4X:
' Click this element. If this causes a new page to load, you should discard all references to this element
' and any further operations performed on this element will throw a StaleElementReferenceException.
' Note that if click() is done by sending a native event (which is the default on most browsers/platforms)
' then the method will _not_ wait for the next page to load and the caller should verify that themselves.
' There are some preconditions for an element to be clicked.
' The element must be visible, and it must have a height and width greater than 0.

Documents for .Submit
B4X:
' If this current element is a form, or an element within a form, then this will be submitted to the remote server.
' If this causes the current page to change, then this method will block until the new page is loaded.

After submit, as it block further code execution until page is loaded, you can check what URL is with:
B4X:
Dim CurrentUrl As String = Selenium.CurrentUrl

There is a lot of possibility to change URL, like JS redirect, that cannot be detected with event.
Use Selenium.CurrentUrl to check URL location.

Event NavigationFinished will fire only on: .NavigateTo, .NavigateBack, .NavigateForward, .NavigateRefresh

You can also inject JS in page and get result back, that offer a lot of possibilities.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
In my case .submit causes the form page to reload with emptied fields, so I am forced to use the .click method

Thanks for the extra info
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I have a extra question.
Can chrome be opened inside a from? I would like to "encapsulate" the website within a form
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
It is possible that click on the button call JS and then JS send form submit to server with some safety parameters to protect form from bots submissions. In that case you cannot call submit directly.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
It is possible that click on the button call JS and then JS send form submit to server with some safety parameters to protect form from bots submissions. In that case you cannot call submit directly.
yes, I think it uses (a lot of) js
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
I have a extra question.
Can chrome be opened inside a from? I would like to "encapsulate" the website within a form

Chrome For Testing is EXE, you cannot embed it in B4J.
Selenium use local websocket to make communication with Chrome.
You can hide Chrome to be invisible, you need to AddArgument BEFORE you Initialize Selenium:
B4X:
Selenium.AddArgument("--headless") 'Run in headless mode, without a UI or display server dependencies.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
cool, that may solve my issue!!!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…