Skip to content

Instantly share code, notes, and snippets.

@source-nerd
Created February 29, 2020 16:31
Show Gist options
  • Save source-nerd/e111aaf65f98666fc09b35194fa53e88 to your computer and use it in GitHub Desktop.
Save source-nerd/e111aaf65f98666fc09b35194fa53e88 to your computer and use it in GitHub Desktop.
France schengen visa appointment bot
from selenium import webdriver
import time
from selenium.webdriver import ActionChains
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
def initialize():
size = driver.find_elements_by_tag_name("frame")
driver.switch_to.frame("BODY_WIN")
frameset_elem = driver.find_element_by_xpath("html/frameset")
all_inner_frames = frameset_elem.find_elements_by_tag_name("frame")
wait.until(EC.presence_of_element_located((By.ID, 'MENU_WIN')))
time.sleep(5)
# Go through the menu first and click on booking an appointment
driver.switch_to.frame(all_inner_frames[0])
frameset_tbody_elem = driver.find_element_by_xpath("html/body/div/table/tbody")
tr_elem_tags = frameset_tbody_elem.find_elements_by_tag_name("tr")
inner_tr_table = tr_elem_tags[1].find_element_by_xpath("td/table/tbody")
all_inner_trs = inner_tr_table.find_elements_by_tag_name("tr")
second_tr = all_inner_trs[1].find_element_by_xpath("td/div/table/tbody")
action = ActionChains(driver)
firstLevelMenu = second_tr.find_element_by_xpath("tr/td")
firstLevelMenu.click()
time.sleep(3)
def proceed_next():
driver.switch_to.default_content()
size = driver.find_elements_by_tag_name("frame")
driver.switch_to.frame("BODY_WIN")
frameset_elem = driver.find_element_by_xpath("html/frameset")
all_inner_frames = frameset_elem.find_elements_by_tag_name("frame")
driver.switch_to.frame(all_inner_frames[1])
frameset_tbody_elem = driver.find_element_by_xpath("html/body/form/table/tbody")
inner_tr = frameset_tbody_elem.find_elements_by_tag_name("tr")
third_tr = inner_tr[2].find_element_by_xpath(
"td/table/tbody[@id='page_conditions']/tr/td/table[@class='CGcodetresclair zonegroupe']/tbody")
contenugroupe_trs = third_tr.find_elements_by_tag_name("tr")
contenugroupe_trs3 = contenugroupe_trs[2].find_element_by_xpath("td/table/tbody")
final_tr = contenugroupe_trs3.find_elements_by_tag_name("tr")
chkbox_tr = final_tr[2].find_element_by_xpath("td/span/input")
chkbox_tr.click()
print("Finding button elem")
next_btn = driver.find_element_by_id("boutonSuivant_link")
print(next_btn.get_attribute('outerHTML'))
next_btn.click()
pass
if __name__ == "__main__":
appointment_found = False
while not appointment_found:
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--ignore-certificate-errors')
driver = webdriver.Chrome("D:\\chromedriver_win32\\chromedriver.exe", options=options)
driver.get(
'https://pastel.diplomatie.gouv.fr/rdvinternet/html-4.02.00/frameset/frameset.html?lcid=1&sgid=102&suid=1'
)
wait = WebDriverWait(driver, 3)
# Initialize
initialize()
# Click on Next
driver.switch_to.default_content()
proceed_next()
try:
wait.until(EC.alert_is_present(),
'Timed out waiting for Alert creation ' +
'confirmation popup to appear.')
alert = driver.switch_to.alert
print("Alert shows following message: " + alert.text)
alert.accept()
print("alert accepted")
# Click on previous
prev_btn = driver.find_element_by_id("boutonPrecedent_link")
prev_btn.click()
time.sleep(15)
except TimeoutException:
print("---------- APPOINTMENT AVAILABLE -----------------------")
appointment_found = True
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
driver = webdriver.Chrome("D:\\chromedriver_win32\\chromedriver.exe", options=options)
driver.get(
'https://pastel.diplomatie.gouv.fr/rdvinternet/html-4.02.00/frameset/frameset.html?lcid=1&sgid=102&suid=1'
)
wait = WebDriverWait(driver, 3)
# Initialize
initialize()
# Click on Next
driver.switch_to.default_content()
proceed_next()
@amansheaven
Copy link

The script it outdated with find_element_by being depreciated in new Selenium

@AlexLir20
Copy link

this monitor is not suitable for https://consulat.gouv.fr/en/ambassade-de-france-en-irlande/appointment?name=Visas. I have tried to change a new version. but failed. do you have any ideas to re-write?

@kkk199
Copy link

kkk199 commented Apr 28, 2023

@source-nerd Can you please please update this one ? I am really having hard time to book appointment...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment