编码的用户界面 - 并不总是点击正确的元素
您好,
我对编码ui很新,我正在努力解决一个奇怪的问题,即用鼠标点击选择了错误的字段。
I'm quite new to coded ui and I'm struggling with a strange issue where the incorrect field is being selected with a mouse click.
测试网站是:
http://www.phptravels.net/
http://www.phptravels.net/
其中一个页面,有一个下拉列表,您可以选择一个国家。
On one of the pages, there is a drop down where you can select a country.
希望你能在这里看到它
http://www.phptravels。 net / hotels / book / Swissotel-Le-Plaza-Basel?成人= 2&孩子= 0& checkin = 22%2F11%2F2017& checkout = 23%2F11%2F2017& roomid = 47& roomscount = 1
http://www.phptravels.net/hotels/book/Swissotel-Le-Plaza-Basel?adults=2&child=0&checkin=22%2F11%2F2017&checkout=23%2F11%2F2017&roomid=47&roomscount=1
我已设法选择下拉列表,但前提是我使用调试器单步调试代码。几乎所有其他时间发生的事情是选择了错误的字段。
I have managed to select the drop down, but only if I step through the code with the debugger. What happened pretty much all other times is that the incorrect field is being selected.
var countryHyperLink = new HtmlHyperlink(_browserWindow);
countryHyperLink.SearchProperties.Add(HtmlHyperlink.PropertyNames.TagInstance, "25");
if (!countryHyperLink.WaitForControlExist(50000))
{
Assert.Fail("Can't find the hyperlink to open the list");
}
Mouse.Click(countryHyperLink);
不正确的元素完全不同,我很难理解它为什么选择这不是指定的那个。
The incorrect element is totally different, and I struggle to see why it is selecting this instead of the one specified.
什么会导致应用程序点击错误的字段?
What would cause the application to click on the wrong field?
我尝试了多种方法,但是这个是我能让它工作的最接近的。
I've tried multiple methods, but this is the closest I can get to making it work.
非常欢迎任何建议。
谢谢
嗨朋友,
感谢你的发帖。
选择县项目的正确步骤应该是:
The right step to select the county item should be like:
a。单击"选择国家/地区"窗格
a. Click the Select country pane
b。显示县的下拉列表
b. Display the dropdown list of counties
c。点击特定国家/地区
c. Click the specific country
对吗?
我发现每次选择不同的国家/地区名称时,选择县内部文字都会不同,
默认:
I found out that every time I selected different country name, the Select county inner text will be different, default:
选择国家后,getfile / 1172616">
,选择国家/地区窗格的内部文本将为:
after I choose a country, the inner text of Select country pane will be:
所以如果我们需要自动化再次使用相同的代码选择相同的代码,它肯定会失败,因为Select Country窗格的SEARCH PROPERTY现在不同了,所以我们必须确保默认的内部文本是我们在
代码中指定的内部文本。
so if we need automation the to select the same with the same code again, it will fail definitely, because the SEARCH PROPERTY of Select Country pane is different now, so we have to make sure that the default inner text is the one we specified in our code.
我只是使用编码的UI测试版本:
I simply use coded UI test build:
选择我需要操作的控件并将其添加到 UIMap ,然后如果可以
编写代码 ,如下所示以实现自动化:
to select the control I need operate and add them to UIMap, then if could just write code like below to implement the automation as yours:
[TestMethod]
public void CodedUITestMethod1()
{
Mouse.Click(UIMap.UICodedUIHowtoverifyifWindow.UISwissotelLePlazaBaseDocument.UISelectCountryPane.UISelectCountryHyperlink);
Mouse.Click(UIMap.UICodedUIHowtoverifyifWindow.UISwissotelLePlazaBaseDocument.UISelect2dropPane.UIChinaPane);
}
it只要确保默认的INNERTEXT OF选择国家/地区是选择国家/地区就行没有问题。
it works with no problem if just make sure the default INNERTEXT OF Select Country is Select Country.
致以最好的问候,
Fletcher