0

It keeps show me the same error:

NameError: name 'close' is not defined

I tried also with quit() and it works, but i need to close just one browser.

Code:

def browser_func():
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    username = "USER"
    password = "PASS"
    driver = webdriver.Chrome('C:/Users/cimin/Downloads/chromedriver_win32/chromedriver')
    driver.get("LINK")
    element = driver.find_element_by_xpath("//input[@name=\"username\"]")
    element.send_keys(username)
    element = driver.find_element_by_xpath("//input[@name=\"password\"]")
    element.send_keys(password)
    element.send_keys(Keys.RETURN)
    element = driver.find_element_by_xpath('//*[@id="module-2970"]/div/div/div[2]/div[1]/a/span')
    element.click()
    if input('done?') == 'y':
        close()

browser_func()

Some suggestions?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
ToboBaldo
  • 15
  • 4

2 Answers2

3

Try this for Python 3.x -

driver.close()

quit() is a Python keyword and instead of suspending selenium it will exit the Python program altogether. Try 'driver.close()' or 'driver.quit()' for closing selenium tabs. More info here

1

close() method is defined as a remote webdriver method.

  • close(): Closes the current window.

So effectively you need to stop calling:

close()

and invoke close() method through the WebDriver instance, i.e. driver as follows:

driver.close()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352