创建一个脚本,该脚本将登录到下面的站点并自动将值记录到 Web 表单中。问题是,一旦我登录,登录页面是空白的(即它加载标题但仅此而已)。我的代码如下:
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
browser = webdriver.Firefox(profile)
browser.get('https://cmsdb.darkcosmos.org/experiments/run/new')
print('Connected to Server')
time.sleep(2) # Wait for page to load
login_button = browser.find_element_by_xpath('/html/body/div/div[5]/main/div/div[1]/div/div[3]/button')
login_button.click()
time.sleep(2) # Wait for pop-out to load
browser.find_element_by_xpath('//*[@id="username"]').send_keys(username)
browser.find_element_by_xpath('//*[@id="password"]').send_keys(password)
login_attempt = browser.find_element_by_xpath('/html/body/div/div[4]/div/div/div/div/div/form/button[1]')
login_attempt.submit()
print('Logged In')
time.sleep(2) # Wait for new page to load
browser.find_element_by_xpath('//*[@id="title"]').send_keys('Title') # Code breaks here. It cannot find the title entry area because the new page is blank.
我试过制作一个 Firefox 配置文件,给页面加载时间,并关闭证书。当我手动登录时它加载得很好。在此先感谢您的帮助!