Selenium FindElement块,直到文件上传完成。

问题描述 投票:2回答:2

| [{name: this.value}], fileInput: $(this) });});

So, now after creating the tmpId input element, my selenium script does this:FindElementThis triggers add callback, checks the file, changes to the template to 'progress', and starts the upload.Assuming the upload takes 60 seconds, the server will respond and then the template will trigger to 'finish'

The problem is that although:

returns 'immediately', so I call

And this BLOCKS until the file upload is complete (60 seconds). Even though the progress bar is updating.

<input id="fileUpload" type="file" name="files[]" accept="video/quicktime,video/x-ms-wmv">
<lablel for="fileUpload">Select a file</label>

And then returns success.

jquery('#fileUpload').fileupload(self.fileUploadOptions);

Because I have this progress template I want to validate, I would really like to access the DOM during the upload.data.submit()Any thoughts?

  1. The Short: When I trigger a file upload using SendKeys(path) to a proxy element (placed on by ExecuteScript) that then proxies to my hidden through the jquery.fileupload plugin, the file uploads ...
  2. Is the form being submitted anywhere in the process? I mean is the submit being triggered anywhere or refresh or click on elemnet or similar? The thing is that webdriver is a blocking API and when loading
  3. 当我使用SendKeys(path)触发一个文件上传到一个代理元素(由ExecuteScript放置),然后通过jquery.fileupload插件代理到我的hidden时,文件上传得很好,但当我尝试并发出一个 "我的文件 "的命令时,我就会发现,我的文件上传得很好。
  4. ,它阻挡在服务器响应之前。
  5. 长。
  6. 我使用的是2.4版本的C#网页驱动,默认的firefox驱动,以及jquery文件上传插件(蓝色imp)。

流程开始时,点击一个按钮,打开一个 "概览对话框",里面有我的

  1. 组成对话框后,我有

    正常的用法是让用户点击标签,从而触发输入,然后触发并添加回调,回调检查sizetypes,如果确定,则变为PROGRESS对话框,并进行

  2. .

    进度一直持续到响应,这时最后的对话框会显示一些结果,可以用另一个按钮驳回。

所以,简单来说

var path="\path\to\files";
var tmpInput = WebDriver.FindElement(By.Id("tmpId));
tmpInput.SendKeys(path);

打开一个对话框

将对话框中的模板设置为介绍

tmpInput.SendKeys(path);

选档

var a = WebDriver.FindElement(By.Id("tmpId"));

将对话框中的模板改为进度

启动ajax(或iframe)上传。

在对话框中更改模板完成

Selenium无法访问fileUpload输入(隐藏),所以为了让Selenium触发文件上传,我最后不得不执行一些类似这样的脚本。

添加一个新的输入元素
javascript file-upload selenium jquery-file-upload
2个回答
1
投票

$('#tmpId').bind('change', function (e) { $('#fileUpload').fileupload('add', { files: e.target.files 刷新或类似的触发,webdriver会检查各种东西来检查页面是否完成加载(即document.readyState == 'complete')等等。

总之,应该是可以覆盖这个策略的,你可以试着研究一下。页面加载策略.


1
投票

如果你想等待ajax操作,你可以使用类似这样的方法。

            var ajaxIsComplete = javaScriptExecutor != null && (bool)javaScriptExecutor.ExecuteScript("return jQuery.active == 0");

如果页面中没有ajax活动,上面的代码将返回true,但我建议你使用wait

        var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(time));
        wait.Until(ElementIsClickable(locator);

如果你想要你给出等待的时间,如60秒,120秒等,它将在这段时间内等待,直到元素被解封。

我认为这是最好的解决方案,如果你认为我误解了你的阙,请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.