selenium 2.0 'NoneType' object has no attribute 'send_keys'
来源:互联网 发布:好运来返奖统计软件 编辑:程序博客网 时间:2024/06/11 15:13
先把出错的代码贴出来
all_handles=action.window_handlesfor handle in all_handles: if handle!=orginal_page: action.switch_to.window(handle) action.switch_to.frame("frameMu_0") for lists in types: for pl in product_list: pl=pl.decode('utf-8') action.find_element_by_id("pName").send_keys(pl) action.find_element_by_id("btn2").click() try: action.find_element_by_name("pId").click() except: action.get_screenshot_as_file("Add_Normal_Product_Error"+date1+"-"+date2+".jpg") with open("Test_Error"+date1+".log",'a+') as ef: print >>ef,"error\t"+date3+"\n没有搜索到相关产品\n" time.sleep(2) action.quit() else: action.find_element_by_id("pName").clear() action.switch_to.default_content() action.find_element_by_id("button2").click()action.switch_to.window(orginal_page)action.switch_to.frame("34")pro=action.find_element_by_css_selector("#contractTab > div.tabs-panels > div:nth-child(1) > div > iframe")action.switch_to.frame(pro)action.find_element_by_css_selector("body > div:nth-child(1) > table > tbody > tr:nth-child(1) > td:nth-child(7) > a").click()time.sleep(2)
执行上面的代码报错:
‘NoneType’ object has no attribute ‘send_keys’
后经高人指点,才知道在循环里切回了default_content,这样再循环的时候就不再frame里面了。
后来高人说应该把iframe写在循环里。虽然按高人说的做了,但是还是没有达到预期的目标。
后来自己又琢磨了一下,就有了下面的代码:
all_handles=action.window_handles for handle in all_handles: if handle!=orginal_page: action.switch_to.window(handle) action.switch_to.frame("frameMu_0") for pl in product_list: pl=pl.decode('utf-8') action.find_element_by_id("pName").send_keys(pl) action.find_element_by_id("btn2").click() try: action.find_element_by_name("pId").click() except: action.get_screenshot_as_file("Add_Normal_Product_Error"+date1+"-"+date2+".jpg") with open("Test_Error"+date1+".log",'a+') as ef: print >>ef,"error\t"+date3+"\n没有搜索到相关产品\n" time.sleep(2) action.quit() else: action.find_element_by_id("pName").clear() all_handles=action.window_handles for handle in all_handles: if handle!=orginal_page: action.switch_to.window(handle) action.find_element_by_id("button2").click()action.switch_to.window(orginal_page)action.switch_to.frame("34")pro=action.find_element_by_css_selector("#contractTab > div.tabs-panels > div:nth-child(1) > div > iframe")action.switch_to.frame(pro)action.find_element_by_css_selector("body > div:nth-child(1) > table > tbody > tr:nth-child(1) > td:nth-child(7) > a").click()time.sleep(2)
也是按照高人指点的思路,只是稍作改动,不再返回iframe的上层,重新获取了一下窗口的句柄,然后在操作。这样就解决了报错的问题。
0 0
- selenium 2.0 'NoneType' object has no attribute 'send_keys'
- AttributeError: ‘NoneType’ object has no attribute ‘clone’
- AttributeError: 'NoneType' object has no attribute 'clone'
- python : 'NoneType' object has no attribute 'recv'
- AttributeError: 'NoneType' object has no attribute
- AttributeError: 'NoneType' object has no attribute 'startswith'
- Python: Attribute Error - 'NoneType' object has no attribute 'something'
- python __def__ Exception AttributeError: "'NoneType' object has no attribute
- python __def__ Exception AttributeError: "'NoneType' object has no attribute
- [Python][转]Exception AttributeError: "'NoneType' object has no attribute
- Exception AttributeError: "'NoneType' object has no attribute
- python PIL bug: 'NoneType' object has no attribute 'bands' (解决)
- scapy AttributeError: 'NoneType' object has no attribute 'route'解决办法
- python使用PIL库报错,'NoneType' object has no attribute 'bands'
- AttributeError: 'NoneType' object has no attribute 'sc' 解决方法!
- AttributeError: 'NoneType' object has no attribute 'sc' 解决方法(二)
- Scraper_compare( 'NoneType' object has no attribute 'group')
- AttributeError: 'NoneType' object has no attribute 'execute' 错误的解决
- 开发APP接口,PHP在Apache下一直返回500错误的原因
- String、StringBuilder、StringBuffer和CharSequence的区别
- 基于SpringMVC下的Rest服务框架搭建【1、集成Swagger】
- 安卓开发接入微信支付功能的详细步骤(手把手教你一步一步接入,适合小白)
- 当压测遇见奥运 ——游戏服务器如何在上线时面对用户的洪荒之力
- selenium 2.0 'NoneType' object has no attribute 'send_keys'
- AndroidStudio在gradle文件中修改debug签名为正式签名
- IT-linux-top系列--top静态使用
- 备忘!!
- poj 2676 Sudoku
- 虚拟机NAT模式下ping外网
- objective-c ——代码块
- Java重难点面试(二)
- 加速WordPress网站的12个方法