我正在尝试单击文本“登录或”,以便我可以自动登录模块。但我只是陷入了第一步:(
代码
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.android.AndroidDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class searsLogin {
AndroidDriver driver;
@BeforeTest
public void setup() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "ccdcb242");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "ANDROID");
capabilities.setCapability(CapabilityType.VERSION, "5.1.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.sears.android");
capabilities.setCapability("appActivity", "com.android.sears.activity.MenuDrawerActivity");
driver = (AndroidDriver) new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
}
@Test
void execution()
{
// driver.findElementByName("Sign in or").click();/// contains method
// boolean res = driver.findElement(By.name("Sign in or")).isDisplayed();
//boolean res = driver.findElement(By.xpath("//*[contains(text(),'Sign in or')]")).isDisplayed();
driver.findElement(By.partialLinkText("Sign in or")).click();
}
@AfterTest
public void end()
{
driver.quit();
} }
异常消息
java.lang.NoClassDefFoundError: org/openqa/selenium/HasTouchScreen
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
答案 0 :(得分:0)
您正在使用WEB定位器进行移动设备。 此操作的正确XPath将遵循:
By.xpath("//*[@text='Sign in or']")
答案 1 :(得分:-1)
在Appium v1.5.3 - Android中,要点击定位器“名称”,请尝试使用:
driver.findElementByAndroidUIAutomator(“new UiSelector()。text(\”Locator name \“)”)。click();
对于提到的截图 :driver.findElementByAndroidUIAutomator(“new UiSelector()。text(\”登录或\“)”)。click();