1

I am trying to get the adresses for all postal access points in Belgium from this site: https://www.ibpt.be/en/consumers/post/cartography

I am using Selenium with python 3, and I can't seem to get it to work, even though it normally works on other sites. I figure it might be because the map is special in some way? (But I thought this is when Selenium is actually necessary).

Below is the very simple code I am trying to get to work (eventually I need to also paste a zip code and save the results, but first off, I can't even get it to click the search button).

Anyone who can help? (btw, if there is an easier and faster way to do this (without Selenium), please do share).

driver = webdriver.Chrome(r"XXX\chromedriver")
driver.get("https://www.ibpt.be/en/consumers/post/cartography")

time.sleep(3)

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,'body > app-root > div > app-filter > div > div.content > div > form > div.max-height-search-button > div > input')))
time.sleep(3)
ActionChains(driver).move_to_element(driver.find_element_by_css_selector('body > app-root > div > app-filter > div > div.content > div > form > div.max-height-search-button > div > input')).perform()
time.sleep(3)
search = driver.find_element_by_css_selector('body > app-root > div > app-filter > div > div.content > div > form > div.max-height-search-button > div > input')
search.click()
  • page sends POST request to url https://www.postalpoint.be/geoserver/post_uat_wfs/wfs to get some data - you can see more details in `DevTool` in Firefox/Chrome – furas Feb 26 '20 at 09:28
  • Does this answer your question? [Selenium and iframe in html](https://stackoverflow.com/questions/18924146/selenium-and-iframe-in-html) – JeffC Feb 26 '20 at 21:15

1 Answers1

0

As the the desired element is within an <iframe> so to invoke click() on the element you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.
  • Induce WebDriverWait for the desired element to be clickable.
  • You can use the following solution:

    • Using CSS_SELECTOR:

      driver.get('https://www.ibpt.be/en/consumers/post/cartography')
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src*='postalpoint']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.search-location-button>input.bt-search[value='Search']"))).click()
      
    • Using XPATH:

      driver.get('https://www.ibpt.be/en/consumers/post/cartography')
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(@src, 'postalpoint')]")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='search-location-button']/input[@class='bt-search' and @value='Search']"))).click()
      
    • Note : You have to add the following imports :

      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.common.by import By
      from selenium.webdriver.support import expected_conditions as EC
      
  • Browser Snapshot:

Belgian_Institute_for_Postal_services


Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352