本文整理汇总了C#中OpenQA.Selenium.Appium.Android.AndroidDriver.FindElementById方法的典型用法代码示例。如果您正苦于以下问题:C# AndroidDriver.FindElementById方法的具体用法?C# AndroidDriver.FindElementById怎么用?C# AndroidDriver.FindElementById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Appium.Android.AndroidDriver
的用法示例。
在下文中一共展示了AndroidDriver.FindElementById方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
AndroidDriver<AndroidElement> driver;
var INIT_TIMEOUT_SEC = TimeSpan.FromSeconds(180);
var Capabilities=new DesiredCapabilities();
var serverUrl = new Uri("http://172.0.0.1:4723/wd/hub");
// Capabilities.SetCapability(CapabilityType.BrowserName,"");
Capabilities.SetCapability(MobileCapabilityType.DeviceName,"Android");
//Capabilities.SetCapability(MobileCapabilityType.AppActivity,"");
//Capabilities.SetCapability(MobileCapabilityType.AppPackage,"");
Capabilities.SetCapability(MobileCapabilityType.AppiumVersion, "1.4.13");
Capabilities.SetCapability(MobileCapabilityType.App,@"C:/sample-code/apps/ApiDemos-debug.apk");
driver=new AndroidDriver<AndroidElement>(serverUrl,Capabilities,INIT_TIMEOUT_SEC);
driver.Manage().Timeouts().ImplicitlyWait(INIT_TIMEOUT_SEC);
driver.FindElementByName("Graphics").Click();
driver.ScrollTo("FingerPaint", "android:id/list");
driver.FindElementByName("FingerPaint").Click();
AndroidElement element = driver.FindElementById("android:id/content");
Point point = element.Coordinates.LocationInDom;
Size size = element.Size;
driver.Swipe
(
point.X + 5,
point.Y + 5,
point.X + size.Width - 5,
point.Y + size.Height - 5,
200
);
driver.Swipe
(
point.X + size.Width - 5,
point.Y + 5,
point.X + 5,
point.Y + size.Height - 5,
2000
);
driver.FindElementByName("Graphics").Click();
driver.ScrollTo("OpenGL ES", "android:id/list").Click();
//driver.FindElementByName("OpenGL ES").Click();
driver.ScrollTo("Touch Rotate", "android:id/list").Click();
//driver.FindElementByName("TouchRotate").Click();
AndroidElement element1 = driver.FindElementById("android:id/content");
driver.Pinch(element1);
driver.Zoom(element1);
Thread.Sleep(2000);
driver.Quit();
}
示例2: Main
//.........这里部分代码省略.........
//Set device name if using emulator
hybirdCapabilities.SetCapability(MobileCapabilityType.DeviceName, "192.168.56.101:5555");
hybirdCapabilities.SetCapability(MobileCapabilityType.PlatformName, "Android");
hybirdCapabilities.SetCapability(MobileCapabilityType.AutomationName, "Appium");
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