Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.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 org.openqa.selenium.NoSuchElementException:无法定位元素:_Java_Selenium - Fatal编程技术网

Java org.openqa.selenium.NoSuchElementException:无法定位元素:

Java org.openqa.selenium.NoSuchElementException:无法定位元素:,java,selenium,Java,Selenium,代码: 错误: 试试下面的代码 public void Test2() throws Exception{ Thread.sleep(5000); driver.findElement(By.id("cboMenu")).click(); driver.findElement(By.xpath(".//*[@id='cboMenu']/option[3]")).click(); 请使用显式等待而不是Thread.sleep5000,如下一个示例中所示。 它将为你提供关于你经历的更清晰的错

代码:

错误:

试试下面的代码

public void Test2() throws Exception{
 Thread.sleep(5000);
 driver.findElement(By.id("cboMenu")).click();
 driver.findElement(By.xpath(".//*[@id='cboMenu']/option[3]")).click();

请使用显式等待而不是Thread.sleep5000,如下一个示例中所示。 它将为你提供关于你经历的更清晰的错误

public void Test2() throws Exception{ 
    new WebDriverWait(driver, 3).until(ExpectedConditions.visibilityOfElementLocated(By.id("cboMenu")))
    driver.findElement(By.id("cboMenu")).click(); 
    driver.findElement(By.xpath(".//*[@id='cboMenu/option[3]")).click();
}
接下来,验证按钮没有出现在不同的iFrame中。如果执行此操作,请将iFrame更改为您在其中创建的元素:

driver.switchTo().frame("IFRAME_ID");
IFRAME_ID取自DOM:

<iframe id="IFRAME_ID">    

这解决了我的问题:

driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        driver.context("WEBVIEW_com.openstream.cueme.services.workbench");
        Thread.sleep(10000);
        driver.findElementById("userId").sendKeys("sysadmin");
        driver.findElementById("CuemePassword").sendKeys("MMNext13#");

您正在尝试查找哪个元素?您可以提供更多详细信息吗?public void Test2抛出异常{Thread.sleep5000;driver.findElementBy.idcboMenu.click;driver.findElementBy.xpath.//*[@id='cboMenu/option[3]。单击;我已经发布了答案。请检查xpath,如果仍然不起作用,那么您是否可以显示我们试图通过xpath检测的元素的HTML代码或完整的错误消息?您是否可以添加相关的HTML代码片段?请添加一些解释以便帮助理解。实际上,web视图在执行测试。当我放置Thread.sleep10000时,它工作正常。driver.contextWEBVIEW_com.openstream.cueme.services.workbench;Thread.sleep10000;driver.findElementByIduserId.sendkeysadmin;driver.findelementbyidcuempassword.sendKeysMMNext13;在自动化下面的场景时,请使用编辑链接添加额外的i你的答案和问题代码是否有任何变化?
<iframe id="IFRAME_ID">    
//element is WebElement    
(JavascriptExecutor)driver.executeScript("arguments[0].scrollIntoView(true);", element); 
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        driver.context("WEBVIEW_com.openstream.cueme.services.workbench");
        Thread.sleep(10000);
        driver.findElementById("userId").sendKeys("sysadmin");
        driver.findElementById("CuemePassword").sendKeys("MMNext13#");