0

Trying to fill out the form of a site and not matter what it can't find the element. I looked to see if maybe it was an iframe issue but I don't think so.

    # For Browser 1
    browser1 = webdriver.Chrome(options=opts, service=Service(ChromeDriverManager().install()))
    browser1.get("https://www.msg.com/ufc-295/")

    browser1.implicitly_wait(2)
    
    first_name = browser1.find_element(By.ID, "field147946152-first")
    last_name = browser1.find_element(By.ID, "field147946152-last")
    email = browser1.find_element(By.ID, "field147946153")
    submit = browser1.find_element(By.ID, "fsSubmitButton5363561")

HTML code of the fields (looks terrible when I copy the html from inspect) so I will add an image.

enter image description here

Link if needed: https://www.msg.com/ufc-295/

kian
  • 13
  • 3
  • Please copy the HTML into a code block (delimited on each end by `\`\`\``), it will look fine then. – Nick Aug 29 '23 at 04:23
  • implicit wait does not help with client side generated context like react use sleep(10) to see if it will resolve if it does take WebdriverWait into consideration https://stackoverflow.com/questions/26566799/wait-until-page-is-loaded-with-selenium-webdriver-for-python – X-_-FARZA_ D-_-X Aug 29 '23 at 04:28

2 Answers2

0

Your code won't work because the website has an iframe tag in the HTML you are trying to access.

One alternative is to go to the form directly:

# the URL in the iFrame tag when you inspect the page
driver.get('https://msg-wmzqo.formstack.com/forms/ufc_295')
driver.find_element('//*[@id="field147946152-first"]).send_keys('First Name') #first name input

Another alternative is discussed here.

Suraj Shourie
  • 536
  • 2
  • 11
0

Switch to iframe then u will be able to find the element

driver.switch_to.frame(driver.find_element(By.XPATH, "//iframe[contains(@class, '_1oz60')]")) #Switching to IFRAME <br>
driver.find_element(By.XPATH,"//*[@id='field147946152-first']").send_keys("name_here")
Yaroslavm
  • 1,762
  • 2
  • 7
  • 15
  • I have another site with an iframe but no url that I can find right now anyways in the iframe, so I will probably use this approach, thanks! – kian Aug 29 '23 at 06:54