0

I try to close the window, in Google Chrome, but get this error

from selenium.webdriver.common.keys import Keys
browser.find_element_by_tag_name('body').send_Keys(Keys.CONTROL + 'w')

but get this error: AttributeError: 'WebElement' object has no attribute 'send_Keys'

2 Answers 2

1

You should import the function before using it. Use this before calling send_Keys:

from selenium.webdriver.common.keys import Keys
Sign up to request clarification or add additional context in comments.

Comments

1

If you want to close browser window you ccaan use below :

driver.close() – It closes the current browser window

driver.quit() –  closes all the browser windows and ends the WebDriver session as well.

To avoid above error you can add below import to your solution:

from selenium.webdriver.common.keys import Keys

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.