使用java的Selenium WebDriver-找不到元素

使用java的Selenium WebDriver-找不到元素,java,selenium,Java,Selenium,我找不到元素 我的代码: public class Web { private static WebDriver webDriver; public static void main(String[] args) throws InterruptedException { { WebDriver driver = new FirefoxDriver(); driver.get("My_link");

我找不到元素

我的代码:

public class Web {


    private static WebDriver webDriver;

    public static void main(String[] args) throws InterruptedException {

        {
            WebDriver driver = new FirefoxDriver();
            driver.get("My_link");
            WebElement event_id;
            event_id = driver.findElement(By.id("urlbox"));
            event_id.sendKeys("12345");
            Thread.sleep(2000);

            WebElement click_go;
            click_go = driver.findElement(By.cssSelector("button"));
            click_go.click();
            Thread.sleep(2000);

            WebElement view_all = (new WebDriverWait(driver, 20)).until(ExpectedConditions.elementToBeClickable(By.id("view-all")));

            view_all.click();




            driver.quit();

        }
    }

    private static void findDynamicElement() {
    }
}
Java错误:由以下原因引起:org.openqa.selenium.NoSuchElementException:无法定位元素:{“方法”:“id”,“选择器”:“查看所有”}

按钮的html代码为:


A
NoTouchElementException
异常通常由两种原因引起。1.您试图查找的元素包含在
中。2.您试图定位的元素在Selenium认为页面已完成加载后正在加载。我的解决方案是什么?是的,它位于。那我该怎么办呢?为什么你要使用线程睡眠,你只是想在页面上找到已经加载的元素,为什么你还要等着找到同一页面上的元素视图?谢谢。我使用了它,它工作了:driver.switchTo().frame(driver.findElement(By.id(“iframe id”));