Home > database >  selenuim not clicking after entering information
selenuim not clicking after entering information

Time:10-08

I'm trying to automate checking on the status of my Turkish Citizenship Application.

Here is my Code :

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver =  webdriver.Chrome(PATH)

driver.get("https://vatan.nvi.gov.tr/moduller/basvuru/basvurudurumbilgi.aspx")
driver.implicitly_wait(7)

first = driver.find_element(by=By.ID , value="ctl00_content_txtBasvuruNo1")

first.send_keys("55555")
first.send_keys(Keys.RETURN)
second = driver.find_element(by=By.ID , value="ctl00_content_txtBasvuruNo2")
second.send_keys("55555")
second.send_keys(Keys.RETURN)

day = driver.find_element(by=By.ID , value="content_txtDogumTarihi_txtGun")
day.send_keys("01")
day.send_keys(Keys.RETURN)

month = driver.find_element(by=By.ID , value="content_txtDogumTarihi_txtAy")
month.send_keys("01")
month.send_keys(Keys.RETURN)

year = driver.find_element(by=By.ID , value="content_txtDogumTarihi_txtYil")
year.send_keys("1990")
year.send_keys(Keys.RETURN)

WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src^='https://www.google.com/recaptcha/api2/anchor']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.recaptcha-checkbox-border"))).click()

driver.implicitly_wait(20)
driver.find_element(by=By.CLASS_NAME , value= "rtbText").click()

The problem is with the last line. After entering my application number (which I replaced by 55555-55555) it's not clicking it. When I run the last line by itself it clicks. I don't know were I messed up.

CodePudding user response:

It's because you entered an iframe and never left the iframe before trying to interact with something outside the iframe.

You need to add the following line before your last line:

driver.switch_to.default_content()

Then you can start clicking things outside the iframe.

The last part of your code might look like this after you added the line:

WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src^='https://www.google.com/recaptcha/api2/anchor']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.recaptcha-checkbox-border"))).click()

driver.switch_to.default_content()

driver.implicitly_wait(20)
driver.find_element(by=By.CLASS_NAME , value= "rtbText").click()

CodePudding user response:

After clicking on the captcha check box, you have to switch to the default content, using:

driver.switch_to.default_content()

Then you need to click on the 'rtbText'.

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.recaptcha-checkbox-border"))).click()

driver.switch_to.default_content()

driver.implicitly_wait(20)
driver.find_element(by=By.CLASS_NAME , value= "rtbText").click()
  • Related