Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
583 views
in Technique[技术] by (71.8m points)

java - get around capcha in selenium

I have a lot of automated tests to run once I've logged into the site I'm unit testing, but I can't (don't have permissions) remove the capcha from the login page.

is there any way to use selenium 2.0 such that I could start the WebDriver instance of, say, firefox, then do the capcha by hand and then have the WebDriver (I use the java jar of the server) "take over" from there?

thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The following snippet:

  1. loads BING homepage
  2. prompts the user to perform a search
  3. once the search results are loaded in the test browser, the user is prompted to press the ENTER key
  4. the first result link from the user's search is clicked

    driver.get("http://www.bing.com");
    
    System.out.println("Loaded BING homepage");
    System.out.println("Search for some term and then press ENTER");
    
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    reader.readLine();
    
    System.out.println("Clicking on the first link ...");
    
    driver.findElements(By.className("sa_wr")).get(0)
          .findElement(By.tagName("a")).click();
    
    Thread.sleep(3000);
    
    driver.quit();
    

You can use similar code to load the login page, prompt the tester to enter CAPTCHA, and then proceed with the test.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...