Page 43: How to solve math captcha in selenium webdriver using java?.
How to solve math captcha in selenium webdriver using java?.
- public class Mathcaptcha {
-
- public static void main(String[] a) throws InterruptedException {
-
- WebDriver driver = new FirefoxDriver();
-
- driver.manage().window().maximize();
-
- driver.get("http://localhost/mathquestion/signin");
-
-
- WebElement username = driver.findElement(By.id("edit-name"));
- username.clear();
- username.sendKeys("username");
-
-
- WebElement password = driver.findElement(By.id("edit-pass"));
- password.clear();
- password.sendKeys("aaaaaa");
-
-
- String mathquestionvalue = driver.findElement(By.xpath(".//*[@id='user-login']/div/fieldset/div/div[2]/span")).getText().trim();
-
-
- String removespace = mathquestionvalue.replaceAll("\\s+", "");
-
- String[] parts = removespace.split("\\+");
- String part1 = parts[0];
- String part2 = parts[1];
- String[] parts1 = part2.split("\\=");
- String part11 = parts1[0];
-
-
- int summation = Integer.parseInt(part1) + Integer.parseInt(part11);
-
-
- WebElement capta = driver.findElement(By.xpath(".//*[@id='edit-captcha-response']"));
- capta.clear();
- capta.sendKeys("" + summation);
-
-
- driver.findElement(By.id("edit-submit")).click();
-
-
- driver.quit();
- }
- }
1 comment:
Great blog. Thanks for sharing such a useful information.
French Classes in ambala
Best PTE Coaching in ambala
Study visa consultants in ambala, Best IELTS Institute in Ambala
Immigration Consultants
Post a Comment