2017-03-09 35 views
0

我试图去以下几点:文件处理蟒蛇硒自动化错误

<button id="plupload" class="newupl" style="position: relative; z-index: 1; opacity: 1;">Add Images</button>in the attached source code 

enter image description here

我使用下面的代码与硒的网络驱动程序,但该文件没有被上传,因为我会喜欢它是:

imageFolder = '/Users/jmath/Desktop/DevelopmentStuff/PythonFiles/climages/' 

for files in os.walk(imageFolder): 
    for imgfile in files[2]: 
     if imgfile.endswith(".jpeg"): 
      print(imgfile) 
      driver.find_element_by_xpath('/button[@class="newupl"').send_keys(imageFolder + imgfile) 
+0

乔纳森,通常情况下,有一个隐藏的元素的地方,实际上是接受文件名“输入”元素。这通常是您必须执行发送密钥的地方。你可以在该元素周围的元素树中查看一下,看看是否可以找到隐藏的输入。它通常具有“文件”的@type属性。 –

回答

0

<button>元素不是你真正需要处理文件上传。正如@AFundeburg指出,你需要处理的是<input type="file">。尝试下面的代码行,让我知道在任何问题时:

driver.find_element_by_xpath('//input[@type="file"]').send_keys(os.path.join(imageFolder, imgfile))