g1oodboy 2017-07-18 06:51 采纳率: 87.5%
浏览 1290
已采纳

python一直提示对象出错怎么办

python一直提示“str”object has no attribute 'find_element_by_id'怎么办

import colorsys
import urllib,os,uuid,re,time
from PIL import Image
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
from StringIO import StringIO

wzj="res"
def openBrowser():#001_2
#global wzj
wzj = webdriver.Firefox()#打开火狐浏览器
#http://bj.gsxt.gov.cn/sydq/loginSydqAction!sydq.dhtml
wzj.get('http://bj.gsxt.gov.cn/sydq/loginSydqAction!sydq.dhtml')
image1_url = wzj.find_elements_by_class_name('gt_cut_bg_slice')[0].get_attribute('style')#获得图片的样式
image1_url=image1_url[23:-38]#1照片URL地址
image2_url = wzj.find_elements_by_class_name('gt_cut_fullbg_slice')[0].get_attribute('style')
image2_url=image2_url[23:-38]#2照片url地址
return [image1_url,image2_url]

def create(locapath,fileName):#001_1
filePath=locapath+'/'+fileName
if not os.path.exists(filePath):
file=open(filePath,'a+')#在网站上下载的时候写入的地址
file.close()
return filePath

def downloadImg(): #001
list = openBrowser()
for i in range(2):#range是一个创建整数列表range(2)代表是从0到2
fileName=str(i)+'_test.jpg'
urllib.urlretrieve(list[i],create('C:/Users/admin/Desktop/', fileName)) #下载到本地
time.sleep(3)

def inputbyid(): #001_3
#输入查询关键词
#:text: Unicode, 要输入的文本
#:element_id: 输入框网页元素id
#keyword_qycx
text=u"百度"
element_id="keyword_qycx"
input_el =wzj.find_element_by_id(element_id)
input_el.clear()
input_el.send_keys(text)
time.sleep(3.5)

def clickbyid(): #001_4
#点击查询按钮
#:element_id: 查询按钮网页元素id
#popup-submit
element_id01="popup-submit"
wzj.find_element_by_id(element_id01).click()
time.sleep(3.5)

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-07-18 15:54
    关注

    wzj.find_element_by_id(element_id)前面加上wzj = webdriver.Firefox()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据