51Testing软件测试论坛
标题:
appium 获取元素空指针问题
[打印本页]
作者:
servleter
时间:
2020-9-9 14:15
标题:
appium 获取元素空指针问题
package appium;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import org.testng.annotations.BeforeClass;
import org.testng.xml.dom.Tag;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
public class APPiumTest {
AppiumDriver driver;
@BeforeClass
public void beforeClass() throws MalformedURLException {
DesiredCapabilities des = new DesiredCapabilities();
des.setCapability("deviceName", "Android Emulator");
des.setCapability("platformName", "Android");
des.setCapability("platformVersoin", "4.4.2");
des.setCapability("appPackage", "com.android.calculator2");
des.setCapability("appActivity", ".Calculator");
driver=new AndroidDriver(new URL("http://localhost:4723/wd/hub"),des);
}
@Test
public void Test() {
System.out.println("开始");
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);//隐式等待
driver.findElementById("com.android.calculator2:id/digit7").click();
driver.findElementById("com.android.calculator2:id/digit4").click();
driver.findElementById("com.android.calculator2:id/plus").click();
driver.findElementById("com.android.calculator2:id/digit1").click();
driver.findElementById("com.android.calculator2:id/digit6").click();
driver.findElementById("com.android.calculator2:id/equal").click();
String num = driver.findElementByClassName("android.widget.EditText").getText();
System.out.println(num);
}
@AfterClass
public void afterClass() {
driver.quit();
}
}
driver.findElementById("com.android.calculator2:id/digit7").click();处开始空指针
作者:
qqq911
时间:
2020-9-10 11:02
把隐式等待换成强制等待2s试试
作者:
bellas
时间:
2020-9-10 11:08
参考下这个链接
http://ask.testfan.cn/question/824
作者:
jingzizx
时间:
2020-9-10 13:35
还没识别吗
作者:
郭小贱
时间:
2020-9-10 17:37
没定位到"com.android.calculator2:id/digit7"这个元素吗?
作者:
szc123qq
时间:
2020-9-30 15:49
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2