Home > Enterprise >  Can I get Selenium web driver to find button
Can I get Selenium web driver to find button

Time:10-15

Okay, so this may seem like a bad program but it is not. This website I am testing is of my own website and I am testing a program to see if my login page and database can handle it under stress of repeated bot accounts; this here is my old site without Google's Captcha code: Screenshot of Captcha with button that should be pressed

I have tried many numerous times trying to find the correct path so that selenium browser can "click" on it and let the Buster extension do it's thing... Can someone help me by adding this extension and helping me locate the correct path?

CodePudding user response:

I tested this Extension at https://www.google.com/recaptcha/api2/demo with Selenium.WebDriver version 4.5.1 and it works fine. Although sometimes this extension can't recognize the captcha and you will need to try again. You can also experiment with delays.

One of the possible solutions:

string reCaptcha = "iframe[title=\"reCAPTCHA\"]";
string recaptchaChallenge = "iframe[title=\"recaptcha challenge expires in two minutes\"]";
string solverButton = "div.button-holder.help-button-holder";
string submitButton = "recaptcha-demo-submit";

ChromeOptions options = new ChromeOptions();
options.AddExtension(@"O:\selenium\buster_captcha_solver_for_humans-1.3.2-chrome.crx");

IWebDriver driver = new ChromeDriver(@"O:\selenium\", options);
driver.Url = "https://www.google.com/recaptcha/api2/demo";

driver.SwitchTo().Frame(driver.FindElement(By.CssSelector(reCaptcha)));
driver.FindElement(By.Id("recaptcha-anchor")).Click();
driver.SwitchTo().DefaultContent();

Thread.Sleep(1000);

driver.SwitchTo().Frame(driver.FindElement(By.CssSelector(recaptchaChallenge)));
driver.FindElement(By.CssSelector(solverButton)).Click();

Thread.Sleep(2000);

driver.SwitchTo().DefaultContent();
driver.FindElement(By.Id(submitButton)).Click();

Thread.Sleep(2000);

driver.Quit();
  • Related