Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
587 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...