在硒中绕过capcha [英] get around capcha in selenium

查看:134
本文介绍了在硒中绕过capcha的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多自动化测试运行,一旦我登录到我单元测试的网站,但我不能(没有权限)从登录页面删除capcha。

是否有任何方法可以使用selenium 2.0,以便我可以启动WebDriver实例,例如firefox,然后手动完成capcha,然后使用WebDriver使用java jar的服务器)接管从那里?



谢谢!

解决方案
$ b


  1. 加载BING首页
  2. 在测试浏览器中加载搜索结果后,执行搜索
  3. ,系统会提示用户按下ENTER键

  4. 从用户搜索的第一个结果链接被点击

      driver.get(http://www.bing.com); 

    System.out.println(Loaded BING homepage);
    System.out.println(搜索某个术语,然后按ENTER键);

    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    reader.readLine();

    System.out.println(点击第一个链接...);

    driver.findElements(By.className(sa_wr))。get(0)
    .findElement(By.tagName(a))。click();

    Thread.sleep(3000);

    driver.quit();


您可以使用类似的代码来加载登录页面,提示测试者输入CAPTCHA,然后继续测试。

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!

解决方案

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.

这篇关于在硒中绕过capcha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆