'The JavaScript-automated prepopulated fields work with the main form
and with stacked and tabular inlines.
Refs #13068, #9264, #9983, #9784.'

def test_prepopulated_fields(self):

    self.admin_login(username='super', password='secret', login_url=reverse('admin:index'))
    self.selenium.get((self.live_server_url + reverse('admin:admin_views_mainprepopulated_add')))
    self.selenium.find_element_by_id('id_pubdate').send_keys('2012-02-18')
    self.get_select_option('#id_status', 'option    two').click()
    self.selenium.find_element_by_id('id_name').send_keys("    this    is    the    mAin    n\xc3\x80M\xc3\xab    and    it's    aw\xce\xb5\xc5\xa1ome\xc4\xb1\xc4\xb1\xc4\xb1")
    slug1 = self.selenium.find_element_by_id('id_slug1').get_attribute('value')
    slug2 = self.selenium.find_element_by_id('id_slug2').get_attribute('value')
    slug3 = self.selenium.find_element_by_id('id_slug3').get_attribute('value')
    self.assertEqual(slug1, 'main-name-and-its-awesomeiii-2012-02-18')
    self.assertEqual(slug2, 'option-two-main-name-and-its-awesomeiii')
    self.assertEqual(slug3, 'main-n\xe0m\xeb-and-its-aw\\u03b5\\u0161ome\\u0131\\u0131\\u0131')
    self.selenium.find_element_by_id('id_relatedprepopulated_set-0-pubdate').send_keys('2011-12-17')
    self.get_select_option('#id_relatedprepopulated_set-0-status', 'option    one').click()
    self.selenium.find_element_by_id('id_relatedprepopulated_set-0-name').send_keys('    here    is    a    s\xc5\xa4\xc4\x81\xc3\x87ke\xc3\xb0            inline    !        ')
    slug1 = self.selenium.find_element_by_id('id_relatedprepopulated_set-0-slug1').get_attribute('value')
    slug2 = self.selenium.find_element_by_id('id_relatedprepopulated_set-0-slug2').get_attribute('value')
    self.assertEqual(slug1, 'here-stacked-inline-2011-12-17')
    self.assertEqual(slug2, 'option-one-here-stacked-inline')
    self.selenium.find_elements_by_link_text('Add    another    Related    prepopulated')[0].click()
    self.selenium.find_element_by_id('id_relatedprepopulated_set-1-pubdate').send_keys('1999-01-25')
    self.get_select_option('#id_relatedprepopulated_set-1-status', 'option    two').click()
    self.selenium.find_element_by_id('id_relatedprepopulated_set-1-name').send_keys('    now    you    haVe    an\xc3\xb6ther            s\xc5\xa4\xc4\x81\xc3\x87ke\xc3\xb0        inline    with    a    very    ...    loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog    text...    ')
    slug1 = self.selenium.find_element_by_id('id_relatedprepopulated_set-1-slug1').get_attribute('value')
    slug2 = self.selenium.find_element_by_id('id_relatedprepopulated_set-1-slug2').get_attribute('value')
    self.assertEqual(slug1, 'now-you-have-another-stacked-inline-very-loooooooo')
    self.assertEqual(slug2, 'option-two-now-you-have-another-stacked-inline-very-looooooo')
    self.selenium.find_element_by_id('id_relatedprepopulated_set-2-0-pubdate').send_keys('1234-12-07')
    self.get_select_option('#id_relatedprepopulated_set-2-0-status', 'option    two').click()
    self.selenium.find_element_by_id('id_relatedprepopulated_set-2-0-name').send_keys('And    now,    with    a    t\xc3\x83b\xc5\xb1la\xc5\x98    inline    !!!')
    slug1 = self.selenium.find_element_by_id('id_relatedprepopulated_set-2-0-slug1').get_attribute('value')
    slug2 = self.selenium.find_element_by_id('id_relatedprepopulated_set-2-0-slug2').get_attribute('value')
    self.assertEqual(slug1, 'and-now-tabular-inline-1234-12-07')
    self.assertEqual(slug2, 'option-two-and-now-tabular-inline')
    self.selenium.find_elements_by_link_text('Add    another    Related    prepopulated')[1].click()
    self.selenium.find_element_by_id('id_relatedprepopulated_set-2-1-pubdate').send_keys('1981-08-22')
    self.get_select_option('#id_relatedprepopulated_set-2-1-status', 'option    one').click()
    self.selenium.find_element_by_id('id_relatedprepopulated_set-2-1-name').send_keys('a    t\xc3\x83b\xc5\xb1la\xc5\x98    inline    with    ignored    ;"&*^\\%$#@-/`~    characters')
    slug1 = self.selenium.find_element_by_id('id_relatedprepopulated_set-2-1-slug1').get_attribute('value')
    slug2 = self.selenium.find_element_by_id('id_relatedprepopulated_set-2-1-slug2').get_attribute('value')
    self.assertEqual(slug1, 'tabular-inline-ignored-characters-1981-08-22')
    self.assertEqual(slug2, 'option-one-tabular-inline-ignored-characters')
    self.selenium.find_element_by_xpath('//input[@value="Save"]').click()
    self.wait_page_loaded()
    self.assertEqual(MainPrepopulated.objects.all().count(), 1)
    MainPrepopulated.objects.get(name="    this    is    the    mAin    n\xc3\x80M\xc3\xab    and    it's    aw\xce\xb5\xc5\xa1ome\xc4\xb1\xc4\xb1\xc4\xb1", pubdate='2012-02-18', status='option    two', slug1='main-name-and-its-awesomeiii-2012-02-18', slug2='option-two-main-name-and-its-awesomeiii')
    self.assertEqual(RelatedPrepopulated.objects.all().count(), 4)
    RelatedPrepopulated.objects.get(name='    here    is    a    s\xc5\xa4\xc4\x81\xc3\x87ke\xc3\xb0            inline    !        ', pubdate='2011-12-17', status='option    one', slug1='here-stacked-inline-2011-12-17', slug2='option-one-here-stacked-inline')
    RelatedPrepopulated.objects.get(name='    now    you    haVe    an\xc3\xb6ther            s\xc5\xa4\xc4\x81\xc3\x87ke\xc3\xb0        inline    with    a    very    ...    loooooooooooooooooo', pubdate='1999-01-25', status='option    two', slug1='now-you-have-another-stacked-inline-very-loooooooo', slug2='option-two-now-you-have-another-stacked-inline-very-looooooo')
    RelatedPrepopulated.objects.get(name='And    now,    with    a    t\xc3\x83b\xc5\xb1la\xc5\x98    inline    !!!', pubdate='1234-12-07', status='option    two', slug1='and-now-tabular-inline-1234-12-07', slug2='option-two-and-now-tabular-inline')
    RelatedPrepopulated.objects.get(name='a    t\xc3\x83b\xc5\xb1la\xc5\x98    inline    with    ignored    ;"&*^\\%$#@-/`~    characters', pubdate='1981-08-22', status='option    one', slug1='tabular-inline-ignored-characters-1981-08-22', slug2='option-one-tabular-inline-ignored-characters')
