使用Edge + Coded UI导航下一页后无法找到控件 [英] Not able to find the control after navigating the next page with Edge + Coded UI

查看:83
本文介绍了使用Edge + Coded UI导航下一页后无法找到控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我使用Coded UI进行自动化,从现在开始我已经整合了Edge,但面临问题,脚本无法找到控件一次 导航到其他页面。请在下面找到我的代码,点击任何超链接。


请帮助...


  public static void ClickHyperLink(string linkName)

        {

           试试
            {

                Playback.PlaybackSettings.AlwaysSearchControls = true;

                BrowserWindow br = new BrowserWindow();

                if(BrowserWindow.CurrentBrowser.ToLower()。Trim()==" ie")

                {

                    br.SearchProperties [UITestControl.PropertyNames.ClassName] =" IEFrame";

                }


               否则

                {

                    br.SearchProperties [UITestControl.PropertyNames.Name] = WinTitle;

                }¥b $ b                HtmlHyperlink Links = new HtmlHyperlink(br);

               试试
                {

                    UITestControlCollection utcc = Links.FindMatchingControls();

                    string _LinkName ="" ;;

                    bool flag = false;

                    if(utcc.Count> 0)

                    {

                        foreach(UITestControl utc in utcc)

                        {

                            if(utc.GetProperty(HtmlHyperlink.PropertyNames.InnerText)!= null)

                            {

                                _LinkName = utc.GetProperty(HtmlHyperlink.PropertyNames.InnerText).ToString()?? "" ;;"
                            }¥b $ b                           否则

                            {

                                _LinkName =" " ;;

                            }


                            if(linkName.Trim()。ToLower()。Replace(" \\\ quot;"")。替换("","")== _LinkName.Trim()。 ToLower()。替换("\\\",
"")。替换(","""))

                            {

                                flag = true;

                                MouseClick(utc);

                               休息;

                            }¥b $ b                        }¥b $ b                        if(!flag)

                        {

                            Assert.Fail("预期控件"+"链接名称+"在页面上不可用。);)
                            WriteLogs("失败","预期控制"+"linkName +"在页面上不可用。);)
                        }


                    }¥b $ b                   否则

                    {

                        Assert.Fail("预期控件"+"链接名称+"在页面上不可用。);)
                        WriteLogs("失败","预期控制"+"linkName +"在页面上不可用。);)
                    }


                }¥b $ b                catch(UITestControlNotAvailableException na)

                {

$
                    Assert.Fail("预期控制"+"链接名+"在页面上不可用。" + na.BasicMessage);

                    WriteLogs("失败","预期控制"+"linkName +"在页面上不可用。);)
                }¥b $ b                catch(UITestControlNotFoundException nf)

                {

                    Assert.Fail(页面上未找到"预期控制"+ + linkName +"。"+ nf.BasicMessage);

                    WriteLogs("失败","预期控制"+ + linkName +"未在页面上找到。");

                }¥b $ b               试试
                {

                    Playback.Wait(5000);

                    WinTitle = br.Title.Replace(" - Google Chrome","")。Replace(" - Internet Explorer","");

                }¥b $ b                catch {}

            }¥b $ b            catch(PlaybackFailureException e)

            {

                Assert.Fail(e.Message);

                WriteLogs("失败",e.BasicMessage);

            }¥b $ b        }




谢谢


AL


                

解决方案

朋友,


感谢您的帖子。


我可以问你身边的Edge版本吗?


正如我今天早上测试的那样,我仍然有一个例外,表明控制被阻止了。


经过深入调查后,我发现我的问题与 MicrosoftWebDrive                   


我最终测试了版本, Edge版本 10240和14393 ,两者现在都可以正常使用。


我们打开  此页面首先,您会看到 列出驱动程序:




只有10204版本与MSI ,  无法生成安装时默认 文件夹。所以我们需要先下载它。





如果我们的边缘是10204 ,我们可以安装它并将 MicrosoftWebDriver.exe
复制到跨浏览器selenium组件文件夹。



但是如果我们使用任何其他版本,我们需要下载相应版本的网络驱动程序并替换
Microsoft网络驱动程序文件夹中的驱动程序




注意:我已经在我身边测试了两个以上的版本,并且不确定另一个版本是否也可以正常运行。如果它可以在你的最后工作,请告知我们。




祝你好运,


Fletcher 










  



 







 



 








Hello,

I am using Coded UI for automation from last one year now i have incorporated Edge also, but facing issue the script is not able to find the control once  navigate to the other page. Please find my code below to click on any hyperlink present.

Please help...

 public static void ClickHyperLink(string linkName)
        {
            try
            {
                Playback.PlaybackSettings.AlwaysSearchControls = true;
                BrowserWindow br = new BrowserWindow();
                if (BrowserWindow.CurrentBrowser.ToLower().Trim() == "ie")
                {
                    br.SearchProperties[UITestControl.PropertyNames.ClassName] = "IEFrame";
                }

                else
                {
                    br.SearchProperties[UITestControl.PropertyNames.Name] = WinTitle;
                }
                HtmlHyperlink Links = new HtmlHyperlink(br);
                try
                {
                    UITestControlCollection utcc = Links.FindMatchingControls();
                    string _LinkName = "";
                    bool flag = false;
                    if (utcc.Count > 0)
                    {
                        foreach (UITestControl utc in utcc)
                        {
                            if (utc.GetProperty(HtmlHyperlink.PropertyNames.InnerText) != null)
                            {
                                _LinkName = utc.GetProperty(HtmlHyperlink.PropertyNames.InnerText).ToString() ?? "";
                            }
                            else
                            {
                                _LinkName = " ";
                            }

                            if (linkName.Trim().ToLower().Replace("\r\n", "").Replace(" ", "") == _LinkName.Trim().ToLower().Replace("\r\n", "").Replace(" ", ""))
                            {
                                flag = true;
                                MouseClick(utc);
                                break;
                            }
                        }
                        if (!flag)
                        {
                            Assert.Fail("Expected Control " + linkName + " not Available on page. ");
                            WriteLogs("Failed", "Expected Control " + linkName + " not Available on page. ");
                        }

                    }
                    else
                    {
                        Assert.Fail("Expected Control " + linkName + " not Available on page. ");
                        WriteLogs("Failed", "Expected Control " + linkName + " not Available on page. ");
                    }

                }
                catch (UITestControlNotAvailableException na)
                {

                    Assert.Fail("Expected Control " + linkName + " not Available on page. " + na.BasicMessage);
                    WriteLogs("Failed", "Expected Control " + linkName + " not Available on page. ");
                }
                catch (UITestControlNotFoundException nf)
                {
                    Assert.Fail("Expected Control " + linkName + " not found on page. " + nf.BasicMessage);
                    WriteLogs("Failed", "Expected Control " + linkName + " not found on page. ");
                }
                try
                {
                    Playback.Wait(5000);
                    WinTitle = br.Title.Replace(" - Google Chrome", "").Replace(" - Internet Explorer", "");
                }
                catch { }
            }
            catch (PlaybackFailureException e)
            {
                Assert.Fail(e.Message);
                WriteLogs("Failed", e.BasicMessage);
            }
        }

Thanks

AL

                

解决方案

Hi friend,

Thanks for your post.

May I ask the version of Edge in your side?

As I tested this morning, I still had a exception which indicated the control was blocked.

After a deeper investigation, I found out that my the issue was related to the MicrosoftWebDrive of Edge.

I tested version in my end, Edge version 10240 and 14393, both of them now works fine.

Let's open this page first, you will see the list the driver:

Only 10204 version is with MSI,  could be generated the default folder while installing. so we need download it first.

if our edge is 10204, we could just install it and copy the MicrosoftWebDriver.exe to cross browser selenium components folder.

but if we are using any other version, we need download the corresponding version of web driver and replace the driver in the Microsoft web driver folder.

Note: I've only already tested above two versions in my side, and not sure if the other could also run well. Please let us know if it could work in your end.

Best regards,

Fletcher 

  

 

 

 


这篇关于使用Edge + Coded UI导航下一页后无法找到控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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