简体   繁体   English

org.openqa.selenium.NoSuchElementException:无法找到元素:

[英]org.openqa.selenium.NoSuchElementException: Unable to locate element:

Code: 码:

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

Error: 错误:

org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"cboMenu"}
Command duration or timeout: 31 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'venu-PC', ip: '192.168.1.3', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_51'
Session ID: 0f859bed-35df-4eba-a472-3bc2efec4814
Driver info: org.openqa.selenium.firefox.FirefoxDriver

Please use explicit wait instead of the Thread.sleep(5000), like in the next example. 请使用显式等待而不是Thread.sleep(5000),如以下示例所示。 It will provide you much clearer error regarding what you experience. 它将为您提供有关您所经历的错误的更清晰的错误。

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();
}

Next, verify your button doesn't appear in different iFrame. 接下来,确认您的按钮没有出现在其他iFrame中。 If you do, change the iFrame to the one you element inside: 如果这样做,请将iFrame更改为您内部的元素:

driver.switchTo().frame("IFRAME_ID");

The IFRAME_ID is taken from the DOM: IFRAME_ID来自DOM:

<iframe id="IFRAME_ID">    

You can next change visibilityOfElementLocated to presenceOfElementLocated , that will verify that an element is present on the DOM but does not necessarily mean that the element is visible. 您可以更改旁边visibilityOfElementLocatedpresenceOfElementLocated ,将验证一个元素出现在DOM,但并不一定意味着该元素是可见的。 It can be good clue to know if your webDriver is in the correct scope with the button you try to click. 可以通过单击按钮来了解webDriver是否在正确的范围内,这是一个很好的线索。

Additional tip - scroll the button you want to click on into view. 附加提示-滚动您想要单击的按钮进入视图。 Thats could be also the reason to failure. 那也可能是失败的原因。

//element is WebElement    
(JavascriptExecutor)driver.executeScript("arguments[0].scrollIntoView(true);", element); 

this is solved my issue :) 这解决了我的问题:)

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#");

Try below code 试试下面的代码

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.openqa.selenium.NoSuchElementException:无法找到元素错误 - org.openqa.selenium.NoSuchElementException: Unable to locate element error org.openqa.selenium.NoSuchElementException:无法找到元素: - org.openqa.selenium.NoSuchElementException: Unable to locate element: org.openqa.selenium.NoSuchElementException:无法找到元素:-搜索字段 - org.openqa.selenium.NoSuchElementException: Unable to locate element:- Search field 无法找到元素:org.openqa.selenium.NoSuchElementException - Unable to locate element: org.openqa.selenium.NoSuchElementException webdriver org.openqa.selenium.NoSuchElementException:无法找到元素: - webdriver org.openqa.selenium.NoSuchElementException: Unable to locate element: org.openqa.selenium.NoSuchElementException:没有这样的元素:无法找到元素:无法找到表格标签内的元素 - org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: not able to locate the element inside table tag 代码中的 Selenium Fluent Wait Implementation 仍然给出“org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:” - Selenium Fluent Wait Implementation in the code still gives “org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:” org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element error using Selenium through Java - org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element error using Selenium through Java org.openqa.selenium.NoSuchElementException:没有这样的元素:尝试使用Java通过Selenium登录时无法找到元素 - org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element while trying to login through Selenium with Java 线程“ main”中的异常org.openqa.selenium.NoSuchElementException:无此类元素:无法找到元素:{“ method”:“ id”,“ selector”:“ name”} - Exception in thread “main” org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {“method”:“id”,“selector”:“name”}
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM