我整天都在搜索 stackoverflow 来寻找这个问题的答案。我正在尝试使用 Selenium WebDriver 单击 iframe 并填写注册表单上的字段。由于 Python 自己返回错误“无法定位元素”,我现在尝试使用 JavaScript 进入该领域。
新错误是“raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: u'document.getElementById(...) is null' ;”
关于我做错了什么有什么建议吗?
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())