How to know if form is submitted without errors in puppeteer - web-scraping

I am trying to submit a form and I am testing for cases where the form won't submit due to invalid input. If the zip code I enter is valid, then this line of code will return null because there was no error message.
await self.page.waitForFunction(
'document.querySelector("#adr-zip-error")'
);
However I have to hard code a delay before this or set some kind of timeout to catch this error message.
I tried also checking if the form itself is null in the same way but again, it only works if I check after some amount of time as it takes time for the form to submit.
Is there a way to tell if a form is submitted successfully without using a hard coded delay?

This is not a general solution and is tailored to this problem. You could use waitForResponse
const response = await page.waitForResponse(response => response.url().startsWith("https://app.shipt.com/api/v1/customer_addresses"));
if (response.ok())
//success
or, you could just check input validity:
const invalid = await page.evaluate(() => document.querySelector('#adr-zip').getAttribute('aria-invalid') === "true");

After the submit you could do something like:
await Promise.race([
page.waitFor('#adr-zip-error'),
page.waitForNavigation()
])
and then
let error = await page.$('#adr-zip-error')
will let you know if the error happened first

Related

Next.js: Execute async code before hydration on client-side

I need to load a dayjs locale dynamically on the client side. On the server, I can just require it and it works, but it will always lead to a hydration mismatch because there's no way on the client to wait until the
import(`dayjs/locale/${locale}.js`)
actually completes. Can I somehow tell next to wait for the import before beginning re-hydration on the client (since the server-rendered html is actually correct and rendered with the correct locale)?
I know it has been too long and probably you found the solution but here it is a custom hook I wrote which accepts a callback as an argument and will be called only once before rendering the component. and also returns whatever you return in the callback.
the code is simple. you can read and understand it or even improve it.
the code is right here. the gist page
the typescript code if the link gets broken in future:
const useComponentWillMount = <T>(cb: () => T): T => {
const isMountedRef = useRef(false)
const resultRef = useRef<T>()
if (!isMountedRef.current && typeof window !== "undefined") {
resultRef.current = cb()
}
isMountedRef.current = true
return resultRef.current
}

How to find callback function name from hcaptcha?

I'm trying to bypass hcaptcha without submit button.
So I need to know the callback name function but I can't find it in the source code of the page.
Any idea how to submit my request after received my token thx to a captcha resolver ?
Looks like it's possible for recaptcha : https://gist.github.com/2captcha/2ee70fa1130e756e1693a5d4be4d8c70
But can't find the same solution for hcaptcha.
Thx for the help.
This looks pretty straightforward actually:
$('form').submit()
It's what I did to validate the hcaptcha. But unfortunatly the captcha ask me again to fill it even if I send him a validate token
await page.$eval('textarea', (e, token) => {
e.value = token
}, token)
await page.waitForTimeout(1000 + randomTime()*3)
await page.evaluate(() => document.querySelector('form').submit())

Firebase authenticaiton error handling in unity

I have been struggling to find a solution for this and it seems that i'm doing something in the wrong way due to my limited knowladge, so here is the breakdown of the problem:
public void RegisterNewUser()
{
FetchRegisterInputValues();
if (CheckRegisterDataIntegrity())
{
_auth.CreateUserWithEmailAndPasswordAsync(_email, _password).ContinueWith(task => {
if (task.IsCanceled) {
Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled.");
return;
}
if (task.IsFaulted)
{
HandleRegistrationErrors(task.Exception);
return;
}
// Firebase user has been created.
Firebase.Auth.FirebaseUser newUser = task.Result;
Debug.LogFormat("Firebase user created successfully: {0} ({1})",
newUser.DisplayName, newUser.UserId);
});
}
else if (!CheckRegisterDataIntegrity())
{
HandleRegistrationErrors(new AggregateException("passwords do not match"));
}
}
above is the Registration function that I got straight from Firebase docs, it's very straightforward
the FetchRegisterInputValues(); function gets the email and passwords, the CheckRegisterDataIntegrity() compares the password with the password conformation in the form, and finally HandleRegistrationErrors(task.Exception); is meant to fire a popup panel to show the error,
this is how HandleRegistrationErrors(task.Exception); looks
private void HandleRegistrationErrors(AggregateException errMsg)
{
print("its here from the errors method " + errMsg.Message);
registerErrorPopup.OpenNotification();
registerErrorPopup.description = errMsg.Message;
}
it's using a UI asset from the asset store, the .OpenNotification(); starts the animation and pops it up, and then im just showing the message.
Now, I got two problems, the first is when there is an error encountered by Firebase and the if (task.IsFaulted) Condition is true, the HandleRegistrationErrors function should be called, right?. well that's exactly what happens, except only the print("it's here from the errors method " + errMsg.Message); line gets called and the rest of the function does not execute, I thought at first that its a problem with asset, but I tried doing it manually (created a native UI with unity and used SetActive() method to start the popUp), but again only print method executed, I think its because of the
CreateUserWithEmailAndPasswordAsync is Asynchronous and I should handle errors accordingly, but I really don't know how to go about it and there is no documentation that I could find.
The second problem is how to get the correct Error Message because of the task.Exception.Message always returns me a "One or more errors occurred". while the task.Exception itself gives the right message but it's not formatted correctly.
The first question is the easiest. To update your code with the minimal amount of effort, just replace ContinueWith with ContinueWithOnMainThread will force logic onto the main thread. Also, you should avoid calling task.Result if task.Exception is non-null as it will just raise the exception (see the related documentation).
For the threading related stuff: I go into much more detail about threading with Firebase and Unity here and you can read about the ContinueWithOnMainThread extension here.
For your second issue, the issue you're running into is that task.Exception is an AggregateException. I typically just attach a debugger and inspect this when debugging (or let Crashlytics analyze it in the field), and my UI state is only concerned about success or failure. If you want to inspect the error, the documentation I linked for AggregateException recommends doing something like:
task.Exception.Handle((e) => Debug.LogError($"Failed because {e}"));
Although I would play with .Flatten() or .GetBaseException() to see if those are easier to deal with.
I hope this helps!
--Patrick

INDY Error 212 while executing createPairwise

I am trying to execute createPairwise function of indy-sdk package.
It throws an INDY Error 212 => WalletItemNotFound.
(I also executed createAndStoreMyDid function)
Here is my code
let [myDid, myVerkey] = await sdk.createAndStoreMyDid(await indy.wallet.get(), {});
let theirVerkey = await sdk.keyForDid(await indy.pool.get(), await indy.wallet.get(), theirDid);
let meta = JSON.stringify({
theirEndpointDid: theirEndpointDid,
verified: false // Indicates that the owner of the agent has confirmed they want to stay connected with this person.
});
//FIXME: Check to see if pairwise exists
await sdk.createPairwise(await indy.wallet.get(), theirDid, myDid, meta);
Can anybody help me out?
In your code, there's actually 2 places where IndySDK 1.11.1 can throw 212 WalletItemNotFound.
1. The first is on this line:
let theirVerkey = await sdk.keyForDid(await indy.pool.get(), await indy.wallet.get(), theirDid);
IndySDK will first try to see if the DID under variable theirDid is not one of your DIDs, stored in your wallet. If no, it will try to find this DID on the ledger. If it's still not found, it will throw WalletItemNotFound. You can check out this behaviour in the IndySDK Rust code here:
https://github.com/hyperledger/indy-sdk/blob/v1.11.1/libindy/src/commands/did.rs#L331
2. However I assume this is not actually your case and you having this error coming out from
wait sdk.createPairwise(await indy.wallet.get(), theirDid, myDid, meta);
If you look how is this method implemented in Rust
https://github.com/hyperledger/indy-sdk/blob/v1.11.1/libindy/src/commands/pairwise.rs#L84
you will see that it's calling get_indy_record for both theirDid and myDid you've supplied. Hence you can't create pairwise record without having both DIDs stored in wallet first. You can assure your wallet contains theirDid by calling storeTheirDid method. In
sdk.storeTheirDid(wh, {did:'V4SGRU86Z58d6TV7PBUe6f', verkey: 'GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL'} )
After calling this, you will be able to call createPairwise between you and them without an issue.
IndySDK version / caching note
I think you might be using some older version of IndySDK. In IndySDK 1.11.1 when keyForDid resolves something from ledger, it actually caches this data, so the code you've posted actually worked out of the box for me without an error.

How to allow Flutter to get a value that it stored in a firebase server or any server?

Right now I am using an http 0.11.3+16 and I am able to add a true value to an item on the site using the following function:
if (newAcceptStatus) {
response = await http.put('https://example.com/example1/${selectedOrder.id}/example2/${_authenticatedUser.id}.json?auth=${_authenticatedUser.token}',
body: json.encode(true));
this function is only called when the admin is logged in and the admin is the only one that can change the status of the Boolean, so the value is stored under the admins id and token. so I tried the following to help show if the item was changed by the admin to the user but i keep getting that the value is null when i decode the response with the following function:
Future<Null> checkAccept() async{
http.Response response;
response = await http.get('https://example.com/example1/${selectedOrder.id}/example2/(admin id goes here).json?auth=${_authenticatedUser.token}');
accepted = json.decode(response.body);
}
not sure what i am doing wrong. any help would be appreciated!
I was calling the wrong list of items which were very similar, thus giving me an empty list

Resources