【发布时间】:2024-01-15 20:44:01
【问题描述】:
当我打开网络应用程序时,我会弹出一个窗口。我正在尝试以两种方式点击“允许”按钮:
1) 当我添加权限时:
caps.setCapability("autoGrantPermissions", true);
caps.setCapability("autoAcceptAlerts", true);
......
driver.switchTo().alert().accept();
什么都没发生((
2) 当我尝试通过 XPath 找到它时:
driver.findElement(By.xpath("//android.widget.Button[@text='Allow']")).click();
我收到一个错误:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//android.widget.Button[@text='Allow']"}
这是我从 UI Automator Viewer 截屏:
我发现了这个帖子:Unable to tap the link after tap on Allow button of permission alert in Appium? 但这对我没有帮助。
【问题讨论】:
-
您能否通过选择允许按钮将屏幕截图分享给 UIAutomatorViewer。
-
@AlImran 更新了描述,请看一下
-
你试过
driver.findElement(By.id("android:id/button1")).click();这个吗? -
@AlImran 它不工作,日志中出现错误:
Returned value cannot be converted to WebElement: {message=no such element: Unable to locate element: {"method":"id","selector":"android:id/button1"}
标签: java selenium testing automation appium