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: // 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) { 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 @@

Main Content

-
-
+
+
+ + +
+