0

I've been searching stackoverflow for an answer to this question all day. I'm trying to use Selenium WebDriver to click into an iframe and fill the fields on a registration form. Since Python on its own returns the error "Unable to locate element", I'm now trying to use JavaScript to get into the field.

The new error is "raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: u'document.getElementById(...) is null' ;"

Any advice on what I'm doing wrong?

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0

import string
import random
def id_generator(size=6, chars=string.ascii_uppercase):
     return ''.join(random.choice(chars) for x in xrange(size))

# Create a new instance of the Firefox driver
driver = webdriver.Firefox()

driver.get("http://bostinno.streetwise.co")

driver.find_element_by_link_text("Sign-up").click()

WebDriverWait(driver, 30)

driver.execute_script("document.getElementById('User_firstName').click()")

type(id_generator())

1 Answer 1

2

This should be possible with Selenium API switchto(), which wouldn't require any JavaScript. It might look something like this:

# move into the iframe
iframe = driver.find_elements_by_tag_name('iframe')[0]
driver.switch_to_frame(iframe)

# interact with your element inside the iframe
driver.find_element_by_link_text("Sign-up").click()
driver.find_element_by_id("User_firstName").click()

# do any other steps you need...

# move back out of iframe
driver.switch_to_default_content()
Sign up to request clarification or add additional context in comments.

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.