Selenium受控浏览​​器中的文件上传

时间:2017-04-26 17:50:41

标签: python-3.x google-chrome selenium-webdriver automation ubuntu-14.04

我想使用运行在Ubuntu14上的python在Selenium Controlled Chrome浏览器中上传文件。 我已经看到了选择元素和发送密钥的一些答案,但这对Ubuntu / MAC OS不起作用,因为它没有任何元素来接收密钥。其他解决方案提示Skilui和类似但他们是Jython特定的工具,我也不熟悉它们。 操作系统:Ubuntu 14 32位 语言:Python 3.4 驱动程序:Selenium Web Driver 浏览器:Chrome

HTML code:

<div class="osInfo" data-dojo-attach-event="onClick: uploadFile">
    <div class="ccFontccIcon ic_ic-upload" title="Upload OS Image" data-dojo-attach-point="imageUploadBtn"></div>
    <div class="osFileName" data-dojo-attach-point="imageName">
        <span data-dojo-attach-point="imageFileName">Drag and drop a file here or <span>Select a file from your computer</span></span>
    </div>
    <!--<input data-dojo-attach-point="stateSelect">-->
</div>

我尝试了类似以下的内容:

driver.find_element_by_id("fileUpload").send_keys("C:\myfile.txt")

实际代码:

mode = '4321'
driver.find_element_by_xpath("//*[@class='iosrRepeaterItem empty' and descendant::*[@class='pid-item' " + "and contains(text(), '" + model + "')]]//div[@class='osInfo']").send_keys("/Users/mushoaib/Downloads/car-for-sale\ \(2\).pdf").send_keys(Keys.RETURN)

上面的代码可以点击上传对话框,但在此之后,它什么也没做。

任何帮助都会非常感激。谢谢。

0 个答案:

没有答案