1

I am using selenium with python I want to insert the username and email inputs containing in frame
Here is the link

I am trying to do this but it's not switching into the modal.

 try:
    time.sleep(3)
    driver.switch_to.frame(driver.find_element_by_id("thanksModal"))
    driver.find_element_by_xpath("//input[@type='file']").send_keys("C:\\Users\\user\\Desktop\\Resume.docx")
    driver.find_element_by_id('txtName').send_keys(name)
    driver.find_element_by_id('txtEmail').send_keys(email)
    driver.find_element_by_id('btnSubmit').click()
    time.sleep(5)
except:
    pass
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
bhupathi turaga
  • 297
  • 2
  • 16
  • there is no frame as you provided please add sceens shot of which field in the link profvided – PDHide Jan 13 '21 at 18:25

1 Answers1

1

The elements are within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • Induce WebDriverWait for the desired element to be clickable.

  • You can use either of the following Locator Strategies:

    • Using CSS_SELECTOR:

      driver.get("https://www.collabera.com/find-a-job/search-jobs/job-details/248429-python-developer-jobs-jersey-city-nj/")
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.apply-form")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#txtName"))).send_keys("bhupathi_turaga@stackoverflow.com")
      driver.find_element_by_css_selector("input#txtEmail").send_keys("bhupathi_turaga@stackoverflow.com")
      
    • Using XPATH:

      driver.get("https://www.collabera.com/find-a-job/search-jobs/job-details/248429-python-developer-jobs-jersey-city-nj/")
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='apply-form']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='txtName']"))).send_keys("bhupathi_turaga@stackoverflow.com")
      driver.find_element_by_xpath("//input[@id='txtEmail']").send_keys("bhupathi_turaga@stackoverflow.com")
      
  • Note : You have to add the following imports :

     from selenium.webdriver.support.ui import WebDriverWait
     from selenium.webdriver.common.by import By
     from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

Collabera_iframe


Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352