It is because you are using version of selenium which is greater than 3 or exactly in range of selenium 4 , in this chrome automatically close though you don't add driver.close(). but your code is absolutely right. its just due to chrome version.