2

I am trying to fill out this form automatically using Selenium. The form consists out of two pages, which both need to be filled. One proceeds to the second page by clicking the orange button stating 'Weiter'.

I have the following code,

# load form into chrome, directly via its url
ad_url = 'https://www.immobilienscout24.de/expose/97655130'
form_url_end = '#/basicContact/email'
url = ad_url + form_url_end 
browser = webdriver.Chrome()
browser.get(url)

# code which fills out first page correctly

# switch to second page
window_before = browser.window_handles[0]
browser.find_element_by_xpath(
   '//*[@id="is24-de"]/div[2]/div/div[2]/div[1]/form/div/div/div[4]/div[2]/button',
   ).click()
window_after = browser.window_handles[1]
browser.switch_to.window(window_after)

This codes runs fine until the last line – browser.switch_to.window(window_after), which yields IndexError: list index out of range.

I've followed this answer.

How do I command selenium to focus on the new page?


To fill out the fields in the form, I use e.g for the city field on the first page,

city = browser.find_element_by_id("contactForm-city")
city.clear()
city.send_keys('Berlin')
LucSpan
  • 1,831
  • 6
  • 31
  • 66
  • 1
    I do not see multiple windows on that page, only dialogs and layers. – SiKing Jul 27 '17 at 16:21
  • 1
    Ah... I thought as the second page has a different url it was a 'new' window. How do I command Selenium to focus on the second page? – LucSpan Jul 27 '17 at 16:22
  • 1
    Selenium will "focus" on whatever is currently in the one window. – SiKing Jul 27 '17 at 16:25
  • 1
    If that is correct, then why am I able to fill in the fields on the first page, but using similar code on the second page, I receive a `NoSuchElementException`? I've added the code I use to fill the fields in the question. – LucSpan Jul 27 '17 at 16:32
  • 1
    Ok, just solved it. It needed to wait a bit: https://stackoverflow.com/a/16740004/7326714 – LucSpan Jul 27 '17 at 16:38
  • I do not see any element with `id=contactForm-city` on the second page. – SiKing Jul 27 '17 at 16:39

0 Answers0