From 2f772caaed7aa873dd95d1f19983d111f240b80f Mon Sep 17 00:00:00 2001 From: "daniel_fillol@hotmail.com" <55287657+DanielFillol@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:35:50 -0300 Subject: [PATCH 1/3] feat: add function MakeElementVisible --- goSpider.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/goSpider.go b/goSpider.go index d199b32..03dab9c 100644 --- a/goSpider.go +++ b/goSpider.go @@ -969,6 +969,20 @@ func (nav *Navigator) SaveImageBase64(selector, outputPath, prefixClean string) return base64Data, nil } +// MakeElementVisible changes the style display of an element to nil +func (nav *Navigator) MakeElementVisible(selector string) error { + nav.Logger.Printf("Making CAPTCHA response field with selector: %s visible\n", selector) + err := chromedp.Run(nav.Ctx, + chromedp.Evaluate(fmt.Sprintf(`document.querySelector('%s').style.display = ""`, selector), nil), + ) + if err != nil { + nav.Logger.Printf("Error - Failed to make element visible: %v\n", err) + return fmt.Errorf("error - failed to make element visible: %v", err) + } + nav.Logger.Printf("Element with selector: %s is now visible\n", selector) + return nil +} + // Close closes the Navigator instance and releases resources. // Example: // From 16699f6f997e74ca618360e03cde48cc19e074d4 Mon Sep 17 00:00:00 2001 From: "daniel_fillol@hotmail.com" <55287657+DanielFillol@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:36:05 -0300 Subject: [PATCH 2/3] feat: add test for function MakeElementVisible --- goSpider_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/goSpider_test.go b/goSpider_test.go index daa73c8..16b98c0 100644 --- a/goSpider_test.go +++ b/goSpider_test.go @@ -529,6 +529,44 @@ func TestSaveImageBase64(t *testing.T) { }) } +func TestMakeElementVisible(t *testing.T) { + server := startTestServer() + defer server.Close() + + nav := setupNavigator(t) + defer nav.Close() + + err := nav.OpenURL(server.URL + "/test.html") + if err != nil { + t.Errorf("OpenURL error: %v", err) + return + } + + id, err := nav.GetElementAttribute("#divInfraCaptcha > div > iframe", "data-hcaptcha-widget-id") + if err != nil { + t.Errorf("GetElementAttribute error: %v", err) + return + } + + err = nav.MakeElementVisible("#h-captcha-response-" + id) + if err != nil { + t.Errorf("MakeElementVisible error: %v", err) + return + } + + err = nav.WaitForElement("#h-captcha-response-"+id, nav.Timeout) + if err != nil { + t.Errorf("MakeElementVisible error: %v", err) + return + } + + err = nav.FillField("#h-captcha-response-"+id, "54203432300") + if err != nil { + t.Errorf("FillField error: %v", err) + return + } +} + // Won't pass on test because 2FA requires input on the terminal by the user, for that reason alone the test will fail //// TestLoginGoogle tests google single logon //func TestLoginGoogle(t *testing.T) { From 539664cfe76ba02f7a73b57eb8c2b2b67d4c534d Mon Sep 17 00:00:00 2001 From: "daniel_fillol@hotmail.com" <55287657+DanielFillol@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:37:07 -0300 Subject: [PATCH 3/3] feat: add div with hcaptcha fo MakeElementVisible test --- server/test.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/test.html b/server/test.html index 270ac11..34809c2 100644 --- a/server/test.html +++ b/server/test.html @@ -19,8 +19,12 @@