Aram Khachatryan
Aram Khachatryan

Reputation: 103

Python Selenium - AttributeError: 'WebElement' object has no attribute 'send_Keys'

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

Answers (2)

SeleniumUser
SeleniumUser

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

Mahsa
Mahsa

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

Related Questions