Python Selenium-AttributeError:“ WebElement”对象没有属性“ send_Keys”

时间:2020-04-11 11:35:26

标签: python selenium

我尝试在Google Chrome中关闭窗口,但是出现此错误

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

但是出现此错误: AttributeError: 'WebElement' object has no attribute 'send_Keys'

2 个答案:

答案 0 :(得分:1)

如果要关闭浏览器窗口,请在下面使用ccaan:

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

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

为避免出现上述错误,您可以在解决方案中添加以下导入:

from selenium.webdriver.common.keys import Keys

答案 1 :(得分:1)

使用该功能之前,应先导入该功能。在调用send_Keys之前使用它:

from selenium.webdriver.common.keys import Keys