AttributeError: 'WebElement' object has no attribute 'send_keys'
这个是没问题的代码:用来打开谷歌搜索cheese并退出
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0 # Create a new instance of the Firefox driver
driver = webdriver.Firefox() # go to the google home page
driver.get("http://www.google.com") # the page is ajaxy so the title is originally this:
print driver.title # find the element that's name attribute is q (the google search box)
inputElement = driver.find_element_by_name("q") # type in the search
inputElement.send_keys("cheese!") # submit the form (although google automatically searches now without submitting)
inputElement.submit() try:
# we have to wait for the page to refresh, the last thing that seems to be updated is the title
WebDriverWait(driver, 10).until(EC.title_contains("cheese!")) # You should see "cheese! - Google Search"
print driver.title finally:
driver.quit()
有问题的代码:打开百度首页 搜索并退出
from selenium import webdriver
driver=webdriver.Firefox()
driver.get("http://www.baidu.com")
element = driver.find_element_by_id("kw1")
element.send_keys('test') #这里报错 driver.close()
错误:AttributeError: 'WebElement' object has no attribute 'send_keys'
看提示sendKeys 没有导入包,
目前代码:
from selenium import webdriver
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.common.action_chains import ActionChains driver=webdriver.Firefox()
driver.get("http://www.baidu.com")
ele = driver.find_element_by_name("wd")
print (ele)
ele.send_keys("test") btn = driver.findElement(By.id("su1"));
btn.click() driver.close()
报错提示:
Traceback (most recent call last):
File "D:\pcode\24.py", line 9, in <module>
ele.send_keys("test")
File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 293, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': typing})
File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 370, in _execute
return self._parent.execute(command, params)
File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 166, in execute
self.error_handler.check_response(response)
File "D:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py"
, line 164, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: u'Element is not
currently visible and so may not be interacted with' ; Stacktrace:
正确代码如下:
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
import time # Create a new instance of the Firefox driver
browser = webdriver.Firefox() # open baidu.com
browser.get("http://www.baidu.com") # sleep 2 secs
time.sleep(2) #clean the enter text
browser.find_element_by_id("kw1").clear() #enter something
browser.find_element_by_id("kw1").send_keys("selenium") #submit
browser.find_element_by_id("su1").click() # sleep 2 secs
time.sleep(2) try:
# we have to wait for the page to refresh, the last thing that seems to be updated is the title
WebDriverWait(browser, 10).until(EC.title_contains("selenium")) # You should see "selenium - 百度搜索"
print browser.title finally:
browser.quit()
另外一种写法:
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
import time # Create a new instance of the Firefox driver
browser = webdriver.Firefox() # open baidu.com
browser.get("http://www.baidu.com") # sleep 2 secs
time.sleep(3) #clean the enter text
browser.find_element_by_id("kw1").clear() #enter something
browser.find_element_by_id("kw1").send_keys("selenium") #submit
browser.find_element_by_id("su1").click() # sleep 2 secs
time.sleep(2) #wait for the page
while True:
#if fresh
contains = browser.title.find("selenium") >= 0
if (contains):
break
else:
sleep(1)
#quit
browser.quit()
AttributeError: 'WebElement' object has no attribute 'send_keys'的更多相关文章
- 关于AttributeError: 'NoneType' object has no attribute 'send_keys'
在学web自动化测试时,通过PO模型将特定页面的一些元素及元素操作放在特定页面模块中, 然后提取公共的部分, 如元素等待WebDriverWait, 元素操作send_keys, click, 获取元 ...
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
- AttributeError: 'list' object has no attribute 'write_pdf'
我在可视化决策树,运行以下代码时报错:AttributeError: 'list' object has no attribute 'write_pdf' 我使用的是python3.4 from sk ...
- attributeError:'module' object has no attribute ** 解决办法
写了一个小脚本,执行的时候报错: Traceback (most recent call last): File "F:/test/qrcode.py", line 109, in ...
- AttributeError: 'module' object has no attribute 'TornadoAsyncNotifier'
/*************************************************************************** * AttributeError: 'modu ...
- AttributeError: 'dict_values' object has no attribute 'translate'
/***************************************************************************************** * Attribu ...
- python3 AttributeError: 'NoneType' object has no attribute 'split'
from wsgiref.simple_server import make_server def RunServer(environ, start_response): start_response ...
- 对于AttributeError: 'Flask' object has no attribute 'cli'的解决办法
版权声明:本文为博主原创文章,未经博主允许不得转载. 环境flask-script2.0.5.flask0.10.1 运行官方文档sample 出现问题 c:\kk\flask\examples\fl ...
- AttributeError: 'module' object has no attribute 'Thread'
$ python thread.py starting at: 2015-08-05 00:24:24Traceback (most recent call last): File "th ...
随机推荐
- python语言中的数据类型之列表
数据类型及内置方法 列表: list 可变类型,有序 用途:用来记录多个值(同属性) 定义方式:在[ ]内用逗号分隔开多个任意类型的值 l=['a','b','c'] #l=list(['a' ...
- English Conversation – Checking in at an airport
English Conversation – Checking in at an airport Share Tweet Share Tagged With: Ben Franklin Exercis ...
- 【371】Twitter 分类相关
Bag-of-words model:就是将句子打散成单词的集合. N-gram model:同上,只是按照 n 进行顺序组合. 参考:机器学习实战教程(四):朴素贝叶斯基础篇之言论过滤器 留言板侮辱 ...
- Windows Server 2008 R2微软官方下载
注意:Windows Server 2008 R2仅有64位版本. 以下下载地址为Windows Server 2008 R2 RTM Build 7600.16385的评估版本,此版本可免费试用18 ...
- spring boot 集成Thymeleaf
- js中将类数组转换为数组的几种方法
1.slice方法 最经典的方法,使用Array的slice方法,此方法如果不传参数的话会返回原数组的一个拷贝,因此可以用此方法转换类数组到数组: // 创建一个类数组对象 var alo = {0: ...
- 大型运输行业实战_day11_1_aop理论与aop实际业务操作
1.aop概述 Spring的AOP:什么叫做AOP:Aspect oritention programming(面向切面编程)什么是切面:看图,业务方法 执行前后.AOP的目的:AOP能够将那些与业 ...
- linus上运行jar包文件增删查
package com.osplat.util; import com.alibaba.fastjson.JSON; import com.osplat.bean.Resultmodel; impor ...
- 检查WMI协议是否通的
在APM上的运行执行“wbemtest”,然后在上面的root\sivm前面加RPC不通的机器,先查WMI协议是否是通的
- BOM 对象--location、navigator、screen、history
1.location 对象 location提供了与当前窗口中加载的文档有关的信息,还有一些导航功能.需要注意的是,window.location 和 document.location 引用的是同一 ...