Reputation: 103
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'
Upvotes: 0
Views: 193
Reputation: 4177
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
Upvotes: 1
Reputation: 742
You should import the function before using it. Use this before calling send_Keys:
from selenium.webdriver.common.keys import Keys
Upvotes: 1