Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 驱动程序不等待元素可见_Java_Appium - Fatal编程技术网

Java 驱动程序不等待元素可见

Java 驱动程序不等待元素可见,java,appium,Java,Appium,我在应用程序中遇到了这个问题,AndroidDriver没有等待catch块中的OK按钮(android.widget.button[@text='OK'])出现。代码如下: WebDriverWait wait = new WebDriverWait(driver, 120); if(networkConnection.wifiEnabled()){ try{ WebElement msg = driver.findElementByXPath("//a

我在应用程序中遇到了这个问题,
AndroidDriver
没有等待catch块中的OK按钮(
android.widget.button[@text='OK']
)出现。代码如下:

WebDriverWait wait = new WebDriverWait(driver, 120);
if(networkConnection.wifiEnabled()){
        try{
            WebElement msg = driver.findElementByXPath("//android.widget.TextView[@text='No network connection detected. Please check your Wi-Fi or mobile settings.']");
            if(msg.isDisplayed()){
                wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//android.widget.Button[@text='OK']")));
                WebElement clickOK = driver.findElementByXPath("//android.widget.Button[@text='OK']");
                clickOK.click();
                System.err.println("420;Download detailing file using WiFi connection;Application should be able to download the detailing file to the device;(Result=Failed!)");
            }
        }
        catch(NoSuchElementException e){

            wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//android.widget.Button[@text='YES']")));
            WebElement clickYes = driver.findElementByXPath("//android.widget.Button[@text='YES']");
            clickYes.click();
            wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//android.widget.Button[@text='OK']")));
            WebElement clickOK = driver.findElementByXPath("//android.widget.Button[@text='OK']");
            if(clickOK.getAttribute("text").contains("successfully")){
                clickOK.click();
                System.out.println("420;Download detailing file using WiFi connection;Application should be able to download the detailing file to the device;(Result=Passed!)");
            }
        }
    }
虽然我已将其设置为等待120秒,但仍然出现以下
NoTouchElementException
错误:

Exception in thread "AWT-EventQueue-0" org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.42 seconds
以下是appium日志:

> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding //android.widget.Button[@text='OK'] using XPATH with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"Could not find an element using supplied strategy. ","status":7}
> info: [debug] Condition unmet after 2407ms. Timing out.
> info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":"Could not find an element using supplied strategy. "},"sessionId":"147e3950-c6f9-4790-8f6f-e9ed70a9aaa9"}
> info: <-- POST /wd/hub/session/147e3950-c6f9-4790-8f6f-e9ed70a9aaa9/element 500 2419.570 ms - 230
>info:[debug][BOOTSTRAP][debug]获取了类型为ACTION的命令
>信息:[debug][BOOTSTRAP][debug]获取命令操作:查找
>信息:[debug][BOOTSTRAP][debug]使用上下文ID为multiple:false的XPATH查找//android.widget.Button[@text='OK']
>信息:[debug][BOOTSTRAP][debug]返回结果:{“value”:“无法使用提供的策略找到元素”,“状态”:7}
>信息:[调试]2407毫秒后未满足条件。超时。
>信息:[调试]响应客户端时出现错误:{“状态”:7,“值”:{“消息”:“无法使用给定的搜索参数在页面上找到元素。”,“origValue”:“无法使用提供的策略找到元素。”},“会话ID”:“147e3950-c6f9-4790-8f6f-E9ED70A9AA9”}

>信息:等待应该是元素初始化的一部分

WebElement clickOK=wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//android.widget.Button[@text='OK']")));

您可以在等待之前交换初始化吗。wait.until(ExpectedConditions.visibilityOf(driver.findelementbypath(“//android.widget.Button[@text='OK']));单击确定。单击();我试试看。这样做的权利觉醒者仍然发生。对此有其他想法吗?@karthing23嗨,很抱歉,过去几天我没能回复。我不能测试代码,因为我不在办公室。但这奏效了!谢谢!