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.sstatic.net/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.

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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
well there are few way to get it resolved stackoverflow.com/questions/58872451/… 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.
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.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.