我一直在尝试在谷歌文本框中输入文本。突然出现这个错误。是什么修改/改变 selenium 新?代码:
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(executable_path="C:\\Program Files (x86)\\chromedriver.exe")
driver.get("https://www.google.com/")
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located(By.NAME, "gLFyf")
)
finally:
driver.send_keys("Selenium")
错误:
File "C:\Users\bhatt\OneDrive\Desktop\Sublime\gotta_master_selenium.py", line 15, in <module>
driver.send_keys("Selenium")
AttributeError: 'WebDriver' object has no attribute 'send_keys'
我还有一些错误
```EC.presence_of_element_located(By.NAME, "gLFyf")TypeError: presence_of_element_located() takes 1 positional argument but 2 were given
我整个假期都在想办法,还是想不出办法
2条答案
按热度按时间wwtsj6pe1#
对于第一个错误:
您必须将
send_keys()
函数与webelement而不是webdriver一起使用。语法:
对于第二个错误:
您必须在下面的行中再使用一个括号'()':
kt06eoxx2#
不能将文本
send_keys("Selenium")
发送到Web驱动程序对象driver
。文本应发送到需要使用
driver
定位的特定web元素