2

Hello everyone I need some help. There is URL: http://lisans.epdk.org.tr/epvys-web/faces/pages/lisans/petrolBayilik/petrolBayilikOzetSorgula.xhtml. As you can see in screenshot I need to click checkbox Captcha.

https://i.stack.imgur.com/xjXaA.png

Here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;

namespace AkaryakitSelenium
{
    class Program
    {
        private static string AkaryakitLink = "http://lisans.epdk.org.tr/epvys-web/faces/pages/lisans/petrolBayilik/petrolBayilikOzetSorgula.xhtml";
        static void Main(string[] args)
        {
           
           IWebDriver driver = new ChromeDriver();
            IJavaScriptExecutor js = driver as IJavaScriptExecutor;
            driver.Navigate().GoToUrl(AkaryakitLink);
            var kategoriCol = driver.FindElements(By.CssSelector(".ui-selectonemenu-trigger.ui-state-default.ui-corner-right"));
            var x = kategoriCol[3];
            x.Click();
            var deneme = driver.FindElement(By.Id("petrolBayilikOzetSorguKriterleriForm:j_idt52_1"));
             deneme.Click();
           
            
            var check = driver.FindElement(By.Id("recaptcha-anchor"));
            
            check.Click();
        }
    }
}

And lastly this error that I am facing:

"OpenQA.Selenium.NoSuchElementException: 'no such element: Unable to locate element: {"method":"css selector","selector":"#recaptcha-anchor"}"

Thank you for your help.

Himeleth
  • 23
  • 1
  • 3

2 Answers2

1

The element you are looking for is inside an iframe :

//iframe[@title='reCAPTCHA']

first you need to switch to iframe like this :

new WebDriverWait(driver, TimeSpan.FromSeconds(3)).Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.XPath("//iframe[@title='reCAPTCHA']")));

then you can perform a click on it :

var check = driver.FindElement(By.Id("recaptcha-anchor"));
check.Click();

PS : captchas are not meant to be automated. since Captcha stands for CAPTCHA stands for the Completely Automated Public Turing test to tell Computers and Humans Apart.

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
  • I could click on captcha by the help your tips. I want to ask that Does ad blockers helps captcha to be automated and can we add ad blockers to selenium – Himeleth Jun 24 '21 at 10:51
  • well there are few way to get it resolved https://stackoverflow.com/questions/58872451/how-can-i-bypass-the-google-captcha-with-selenium-and-python and many time this has been asked here at SO. I personally have never automated any captcha cause that'd a bad captcha if I automate :). Having said that if the application belongs within your org. you may ask your developers or OPS to set a environment without captcha, hopefully your test will get passed by that. – cruisepandey Jun 24 '21 at 13:39
  • Thanks for your tips I wanted to automate captcha since I am developing scraper for that website so I made the code for manual captcha solving thing. It waits until captcha is solved. – Himeleth Jun 25 '21 at 11:47
0

You can not bypass captcha with Selenium.
It is designed to avoid automated access to web pages as described here and in many other places.

Prophet
  • 32,350
  • 22
  • 54
  • 79