У меня есть событие onclick кнопки, однако, когда оно запускается, на самом деле кнопка фактически не нажата. Когда я выполняю .isDisplayed (), элемент всегда найден.Тем не менее, по-прежнему тест не проходит.Здесь я хотел нажать кнопку «Не сейчас», но в следующем коде ничего не вышло, что мне делать?
WebElement c=driver.findElement(By.xpath("//android.widget.Button[@resource-id='android:id/button2']"));
if(c.isDisplayed())
{
c.click();
}
Thread.sleep(20000);
driver.findElement(By.xpath("//android.widget.EditText[@text='Email']")).sendKeys("testappium@gmail.com");
Я также попробовал следующий код, но я не работал
driver.findElement(By.xpath("//android.widget.FrameLayout[@bounds='[27,724][1053,1267]']/android.widget.FrameLayout[@bounds='[75,772][1005,1219]']/android.widget.FrameLayout[@resource-id='android:id/content']/android.widget.LinearLayout[@resource-id='android:id/parentPanel']/android.widget.LinearLayout[@resource-id='android:id/buttonPanel']/android.widget.Button[@bounds='[517,1063][777,1207]']")).click();
также пробовал следующий код:
driver.findElement(By.xpath("//*[@class='android.widget.Button' and @bounds='[517,1063][777,1207]']")).click();
ошибка, которую я получаю:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
*** Element info: {Using=xpath, value=//android.widget.EditText[@text='Email']}
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:62)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:428)
at io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:152)
at io.appium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElementByXPath(AndroidDriver.java:1)
at org.openqa.selenium.By$ByXPath.findElement(By.java:353)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:58)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at execution.AppTest.main(AppTest.java:183)
UI Automator Viewer:
