Search code examples
pythonseleniumweb-scrapingdata-miningdata-extraction

No such element exception. Unable to locate element in selenium python


I want to scrape email from https://www.archionweb.be/ on this page https://www.archionweb.be/Public/Company/1930.

Email is protected in the captcha, So idea is to click on the captcha then extract the email. But Whenever I tried to click on the captcha button (I have used both XPath and CSS selector) there is exception:

"no such element: Unable to locate element"

Please If anyone can help me with this.


Solution

  • Since we are Automating even after clicking on I am not a Robot it sometimes gave another re-captcha. Was able to click on the checkbox with below code.

    from selenium import webdriver
    import time
    from selenium.webdriver.common.action_chains import ActionChains
    
    
    driver = webdriver.Chrome(executable_path="path to chromedriver.exe")
    driver.maximize_window()
    driver.implicitly_wait(30)
    driver.get("https://www.archionweb.be/Public/Company/1930")
    time.sleep(5)
    iframe = driver.find_element_by_xpath("//iframe[@title='reCAPTCHA']")
    driver.switch_to.frame(iframe)
    time.sleep(5)
    recaptcha = driver.find_element_by_class_name("recaptcha-checkbox-borderAnimation")
    driver.execute_script("arguments[0].scrollIntoView(true);",recaptcha)
    ActionChains(driver).move_to_element(recaptcha).click().perform()
    time.sleep(2)
    driver.switch_to.default_content()