硒:以多个标签形式输入的数据有时会消失 [英] Selenium: Data entered in form with multiple tabs disappears sometimes

查看:97
本文介绍了硒:以多个标签形式输入的数据有时会消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有复杂数据输入表单的Web应用程序,其中包含一些选项卡,其中包含用于各种配置项目的输入字段.我正在编写一个测试,该测试将数据输入到不同选项卡上的字段中,然后执行保存.输入每个项目时,在继续下一步之前,我将验证数据输入控件是否具有我选择的文本或值.我发现有时但并非总是如此,当我移至另一个选项卡时,前一个选项卡上的字段会丢失我输入的数据.

I have a web app with a complicated data entry form that has some tabs that hold entry fields for various configuration items. I am writing a test that enters data in fields on different tabs and then executes a save. As I enter each item, I verify that the data entry control has the text or value I selected before moving on to the next step. I am finding that sometimes, but not always, when I move to another tab, fields on the previous tab lose the data I had entered.

如何防止这种情况?

我正在Java中将Selenium 2与WebDriver一起使用,并在Firefox中运行测试.

I am using Selenium 2 with WebDriver in java and running tests with Firefox.

我在两个领域遇到麻烦:

I am having trouble with two fields:

一个是简单的文本输入字段 第二个是带有自动完成功能的文本输入框

One is a simple text entry field The second is a text entry box with an autocomplete feature

两个字段都是我在切换选项卡之前输入数据的最后一个字段.在切换制表符之前输入数据的其他字段均不会丢失数据.刚进入新标签页之前,我与之互动的人.

Both fields are the last ones I input data to before switching tabs. None of the other fields that I input data to before switching tabs lose data. Just the ones I interact with right before going to a new tab.

我尝试检查是否在将文本发送到输入字段的方法的末尾加载了JQuery,但这似乎无济于事.检查JQuery的方法返回true,并且有时仍会删除数据.

I have tried checking that JQuery is loaded at the end of the method that sends the text to the input fields, but it doesn't seem to help. The method that checks JQuery returns true and the data is still erased sometimes.

手动输入数据时永远不会发生这种情况,在仅在一个选项卡上输入数据的另一项自动测试中也不会发生这种情况.

This never happens when entering data manually, and it also doesn't happen in another automated test where data is entered on one tab only.

在这里,当输入文本并且没有任何待触发的输入触发自动完成时,这是自动完成字段的html:

Here is the html for the autocomplete field when text has been entered and there is no pending input that has triggered autocomplete:

<div id="s2id_autogen5" class="select2-container select2-container-multi select2">
    <ul class="select2-choices" style="">
        <li class="select2-search-choice">
            <div>
                htm
            </div>
            <a class="select2-search-choice-close" tabindex="-1" onclick="return false;" href="#"></a>
        </li>
        <li class="select2-search-field">
            <input class="select2-input" type="text" autocomplete="off" tabindex="0" style="width: 10px;"></input>
        </li>
    </ul>
</div>

以下是简单文本输入字段的html源:

Here is the html source for the simple text entry field:

<td class="optionValue option_sr_test_object_url">
    <input id="option_d03e6450-5990-4a31-8e84-5b1af89d2c47_sr_test_object_url" type="text" placeholder="e.g. /path/testobject.html" value="/path/test.html">
    </input>
</td>

推荐答案

我终于找到了可靠的方法来阻止这种情况的发生:

I finally found something that reliably prevented this happening:

driver.switchTo().window(driver.getWindowHandle());

driver.switchTo().window(driver.getWindowHandle());

当我在切换制表符之前执行该行时,先前输入的数据未被清除.我不知道为什么会这样,也不记得我是如何找到这个解决方案的.几个月以来,我一直想用这个答案来更新这个问题,但我一直忘了这么做.

When I execute that line before switching tabs, my previously entered data was not cleared out. I don't know why this works, nor do I remember how I found this as a solution. I kept meaning to update this question with this answer for months, but I kept forgetting to do it.

这篇关于硒:以多个标签形式输入的数据有时会消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆