【问题标题】:Selenium WebDriver Automation for Vaadin components用于 Vaadin 组件的 Selenium WebDriver 自动化
【发布时间】:2014-08-08 13:30:09
【问题描述】:

我正在使用 Selenium Java WebDriver 来自动化基于 Vaadin 的 Web 应用程序。当我导航到一个页面并单击一个按钮时,它会打开另一个小窗口,对我来说这看起来不像一个弹出窗口。似乎子窗口是动态添加到主 html 中的。

有人知道如何识别 Selenium 中的 Vaadin 元素吗?

【问题讨论】:

    标签: java selenium-webdriver vaadin


    【解决方案1】:

    试试

    driver.findElement(By.className("v-window")) 用于整个窗口或 driver.findElement(By.className("v-window-contents")) 为窗口内容。

    【讨论】:

    • 它是 v-window-contents。但是使用它也没有运气 - org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"class name","selector":"v-window-contents"}
    【解决方案2】:

    当您创建测试时,请务必在浏览器打开后运行此测试。有时测试开始,但浏览器未打开。我将Thread.sleep(1000); 放在@Before 类中,以确保chrome 已打开。

    @Before
    public void openBrowser() throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", "chromedriver");
        driver = new ChromeDriver();
        driver.get("http://localhost:8000");
        Thread.sleep(1000);
    }
    

    然后

    @Test
    public void testLoginFormExists() {
        WebElement login = driver.findElement(By.id("username"));
        WebElement password = driver.findElement(By.id("password"));
        ...
    }
    

    或者更好的是,检查这个答案:https://stackoverflow.com/a/9430377/1168786

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-06
      • 2015-10-30
      • 1970-01-01
      • 1970-01-01
      • 2016-04-17
      相关资源
      最近更新 更多