public class Mathcaptcha {
public static void main(String[] a) throws InterruptedException {
// Initialize Web driver
WebDriver driver = new FirefoxDriver();
//Maximize browser window
driver.manage().window().maximize();
//Go to Page
driver.get("http://localhost/mathquestion/signin");
// Type username
WebElement username = driver.findElement(By.id("edit-name"));
username.clear();
username.sendKeys("username");
//Type Password
WebElement password = driver.findElement(By.id("edit-pass"));
password.clear();
password.sendKeys("aaaaaa");
// get Math question
String mathquestionvalue = driver.findElement(By.xpath(".//*[@id='user-login']/div/fieldset/div/div[2]/span")).getText().trim();
// remove space if exist
String removespace = mathquestionvalue.replaceAll("\\s+", "");
// get two numbers
String[] parts = removespace.split("\\+");
String part1 = parts[0];
String part2 = parts[1];
String[] parts1 = part2.split("\\=");
String part11 = parts1[0];
// sum two numbers
int summation = Integer.parseInt(part1) + Integer.parseInt(part11);
// Math Capcha value
WebElement capta = driver.findElement(By.xpath(".//*[@id='edit-captcha-response']"));
capta.clear();
capta.sendKeys("" + summation);
//Click on SignIn button
driver.findElement(By.id("edit-submit")).click();
//close browser
driver.quit();
}
}
How to solve math captcha in selenium webdriver using java?.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment