问题描述
限时送ChatGPT账号..我想使用 c# 和 Appium 在 Android 模拟器上自动化移动网站测试.我想在开始时自动化一个简单的测试场景:
1. 启动浏览器
2. 查找元素
3.清除它
4. 发送密钥
I want to automate mobile web site testing on Android emulator using c# and Appium. There is a simple test scenario I want to automate for the start:
1. Start Browser
2. Find an element
3. Clear it
4. Send keys
我的第二步有问题.每次 MSTest 尝试在下面的代码中执行 FindElementById 行时,我都会收到错误消息:无法使用给定的搜索参数在页面上找到元素."
I've got a problem with the second step. Every time MSTest tries to execute FindElementById line in the code below, I get the error: "An element could not be located on the page using the given search parameters."
[TestClass]
public class UnitTest1
{
private DesiredCapabilities _capabilities;
private AndroidDriver _driver;
public void InitializeDriver()
{
Console.WriteLine("Connecting to Appium server");
_capabilities = new DesiredCapabilities();
_capabilities.SetCapability("deviceName", "test_02");
_capabilities.SetCapability(CapabilityType.BrowserName, "Chrome");
_capabilities.SetCapability(CapabilityType.Version, "5.0.1");
_capabilities.SetCapability(CapabilityType.Platform, "Android");
//Application path and configurations
_driver = new AndroidDriver(new Uri("http://127.0.0.1:4723/wd/hub"), _capabilities);
}
[TestMethod]
public void TestMethod1()
{
InitializeDriver();
var element = _driver.FindElementById("com.android.browser:id/url");
element.Clear();
element.SendKeys(@"http://stackoverflow/");
}
}
我从 UIAutomator 获得的方法的输入字符串,如下所示.
Input string for the method I've got from UIAutomator that is shown below.
我为 FindElementById 输入法尝试了几种组合:
com.android.browser:id/url"
ID/网址"
网址"
但没有运气.
I tried several combinations for the FindElementById input method:
"com.android.browser:id/url"
"id/url"
"url"
but no luck.
我的环境:
视窗 8.1
Appium 1.3.4.1
ChromeDriver 2.14.313457
Android 设备监视器 24.0.2
My environment:
Windows 8.1
Appium 1.3.4.1
ChromeDriver 2.14.313457
Android Device Monitor 24.0.2
推荐答案
抱歉误导!!!在浏览器中测试 Web 应用程序的情况下,元素应该像网页上的通常元素一样(而不是像 android.widget.EditText 和 android.widget.Button 这样的一些类).因此,例如尝试以下操作,您将看到一些结果:
Sorry for misleading !!! In case of testing web apps in browser the elements should be located as usual elements on the web page ( not as some classes like android.widget.EditText and android.widget.Button). So try for example the following and you will see some result:
var element = _driver
.findElementByXPath("//input[@id='lst-ib']");
要获取定位器,您应该在桌面上运行浏览器,打开页面并使用一些工具/扩展程序,例如 Firefox 中的 Firebug 或 Chrome 浏览器中的 Firebug Lite.
To get locators you should run the browser on your desktop, open the page and use some tools/extensions like Firebug in Firefox or Firebug Lite in Chrome browser.
这篇关于无法在使用 Appium 和 C# 的 Android 模拟器的浏览器中找到元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论