當前位置: 首頁>>代碼示例>>C#>>正文


C# AndroidDriver.FindElementsByXPath方法代碼示例

本文整理匯總了C#中OpenQA.Selenium.Appium.Android.AndroidDriver.FindElementsByXPath方法的典型用法代碼示例。如果您正苦於以下問題:C# AndroidDriver.FindElementsByXPath方法的具體用法?C# AndroidDriver.FindElementsByXPath怎麽用?C# AndroidDriver.FindElementsByXPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在OpenQA.Selenium.Appium.Android.AndroidDriver的用法示例。


在下文中一共展示了AndroidDriver.FindElementsByXPath方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main


//.........這裏部分代碼省略.........
                hybirdCapabilities.SetCapability(MobileCapabilityType.PlatformVersion, "5.1");
                //if don't want to launch the app in device directly, need set the package and activity
                //otherwise, need specifies the absolute app folder
                hybirdCapabilities.SetCapability(MobileCapabilityType.App, "D:\\AppFolder\\App.apk");

                AppiumDriver<IWebElement> hybirdDriver = new AndroidDriver<IWebElement>(
                    new Uri("http://127.0.0.1:4723/wd/hub"), hybirdCapabilities);

                //Specifies the amount of time the driver should wait when searching for an
                //     element if it is not immediately present
                hybirdDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

                //Get all contexts of the app, check whether include webview
                IList<string> driverContexts = hybirdDriver.Contexts;

                Console.WriteLine("Out put all contexts of the driver");
                foreach(string s in driverContexts)
                {
                    Console.WriteLine(s);
                }
                //Set the context as "WEBVIEW*", then can locate the element as in browser. (can use the API of the Selenium)
                hybirdDriver.Context = driverContexts.Last();

                //Set the timeout again for webview driver.
                hybirdDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

                //Get the Login elements
                IWebElement emailElement = hybirdDriver.FindElement(By.Id("email"));
                IWebElement passwordElement = hybirdDriver.FindElement(By.Id("password"));
                IWebElement loginElement = hybirdDriver.FindElementById("login-button");

                //Set the login information
                emailElement.SendKeys("[email protected]");
                passwordElement.SendKeys("testing");
                IWebElement emailtElementXpath = hybirdDriver.FindElementByXPath("//input[@ng-model=\"login.user.email\"]");

                loginElement.Click();

                //#######Test Case3

                IWebElement friends = (IWebElement)hybirdDriver.FindElement(By.XPath("//div[@class=\"nav-bar-block\" and @nav-bar=\"active\" ]//a[@ui-sref=\"p.main.friends\"]"));
                friends.Click();

                IWebElement search = (IWebElement)hybirdDriver.FindElementById("search");
                search.SendKeys("jack1");

                //Wait for 1 second for the search result
                System.Threading.Thread.Sleep(1000);

                IList<IWebElement> searchResultList = (IList<IWebElement>)hybirdDriver.FindElementsByXPath("//div[@class=\"friend-information auto-truncate ng-binding\"]");
                string searchedPerson1 = searchResultList[0].Text;

                if (searchedPerson1 != "jack1 rose1")
                {
                    Console.WriteLine("Test Case3 failed");
                }
                else
                {
                    Console.WriteLine("Test Case3 pass");
                }

                //#######Test Case4

                //Check the search result of "rose"
                search.Clear();
                search.SendKeys("rose");

                //Wait for 1 second for the search result
                System.Threading.Thread.Sleep(1000);

                try
                {
                    IList<IWebElement> searchResultList2 = (IList<IWebElement>)hybirdDriver.FindElementsByXPath("//div[@class=\"friend-information auto-truncate ng-binding\"]");
                    //IWebElement searchResult_2 = (IWebElement)hybirdDriver.FindElementByXPath("//div[@class=\"search-results\"]/div[3]//div[@class=\"friend-information auto-truncate ng-binding\"]");
                    string searchedPerson2 = searchResultList2[1].Text;

                    if (searchedPerson2 != "jack1 rose1")
                    {
                        Console.WriteLine("Test Case4 failed");
                    }
                    else
                    {
                        Console.WriteLine("Test Case4 pass");
                    }
                }
                catch(Exception ex)
                {
                    Console.WriteLine("Element can not be located!, information is:");
                    Console.WriteLine(ex.Message);
                    Console.WriteLine("Test Case4 failed");
                }

                hybirdDriver.Context = driverContexts.First();

                hybirdDriver.Dispose();
            }
            #endregion

            Console.ReadKey();
        }
開發者ID:TylerTan,項目名稱:Appium-Demo,代碼行數:101,代碼來源:Program.cs


注:本文中的OpenQA.Selenium.Appium.Android.AndroidDriver.FindElementsByXPath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。