6

I try to use selenium webdriver to do one search by image in google so my user didn't need to manually open the browser and paste image url there. but google say

Our systems have detected unusual traffic from your computer network. This page checks to see if it's really you sending the requests, and not a robot.

And give captcha, is there a way to avoid being detected as automation by google using selenium webdriver?

here my code:

@Before
public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "http://images.google.com/searchbyimage?image_url=";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

@Test
public void test2() throws Exception {
    driver.get(baseUrl + "http://somesite.com/somepicture.jpg");
    driver.findElement(By.linkText("sometext"));

    System.out.println("finish");

}

@After
public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
        fail(verificationErrorString);
    }
}
Angga
  • 2,305
  • 1
  • 17
  • 21
  • I thought that's the whole point of using Captcha, detecting robot and we know google works :). With that being said, you may want to take a look at [this](http://stackoverflow.com/questions/18933178/how-to-get-the-data-from-captcha-in-selenium-webdriver) – Saifur Mar 05 '15 at 14:21
  • i know, but i think there is a different between useful bot and harmful bot, like i said i only search one image, not multiple image so my traffic increase. And i only use selenium to simplify my system, so my user didn't need to open browser and copy the URL there manually. – Angga Mar 05 '15 at 16:01
  • But you user does't watch Advertisements. Google don't like it. – talex Mar 05 '15 at 16:10
  • ofcourse they see, they see the same page, the different is just they can see it with one click, no need to copy the url and paste in browser. -.-a – Angga Mar 05 '15 at 17:28

3 Answers3

3

It appear that google detect browser profile to determine something strange has going on or not. for example if you do private browsing with your browser(i test it with firefox and chrome), your browser profile will change to anonymous, so google will find it suspicious and request you to fill captcha.

That case also happen when you run your browser from selenium webdriver.

So you need to set the selenium driver profile to your default profile by using some code like this(currently only work on firefox)

ProfilesIni allProfiles = new ProfilesIni();
WebDriver driver = new FirefoxDriver(allProfiles.getProfile("default"));
Angga
  • 2,305
  • 1
  • 17
  • 21
1

I disagree with @Angga and doubt that Google knows that you're a bot because you're NOT in your default profile.

It's more likely because of this: Can a website detect when you are using selenium with chromedriver?

etayluz
  • 15,920
  • 23
  • 106
  • 151
1

Just add a single line, it will surely help

#For ChromeDriver version 79.0.3945.16 or over

options.add_argument('--disable-blink-features=AutomationControlled') 

#Open Browser

browser = webdriver.Chrome(executable_path='chromedriver.exe',options=option)
Svetlana Levinsohn
  • 1,550
  • 3
  • 10
  • 19
rajat prakash
  • 189
  • 1
  • 6