Selenium Chrome webdriver crashes in a function in Python

Viewed 21

I have downloaded the chromedriver and added the correct path. also tried the code outside of a function, which works fine. When i add it into a function it will run , but crashes after the last click action.

from selenium.webdriver.chrome.service import Service
from selenium import webdriver
from selenium.webdriver.common.by import By
import time


def session():
    service = Service(executable_path="/usr/local/bin/chromedriver")
    driver = webdriver.Chrome(service=service)
    vesteda='https://hurenbij.vesteda.com/'
    driver.get(vesteda)
    username = driver.find_element(By.NAME, 'txtEmail').send_keys('XXXXXXX@gmail.com')   
    password = driver.find_element(By.NAME, 'txtWachtwoord').send_keys('XXXXXX')
    cookiebtn = driver.find_element(By.ID, 'CybotCookiebotDialogBodyButtonAccept').click()
    loginbtn = driver.find_element(By.CLASS_NAME, 'btn-secondary').click()
    zoekopdracht = driver.find_element(By.XPATH,"//a[@href='/zoekopdracht/']").click()

def main():
    session()

if __name__ == "__main__":
    main()
0 Answers
Related