使用selenium找到按钮ID

时间:2016-08-31 07:18:30

标签: java selenium selenium-webdriver

我想使用selenium web驱动程序找到按钮ID。我试过这段代码:

@Test
    public void hello()
    {
        RemoteWebDriver driver = BrowserFactory.getDriver("chrome", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");

        driver.get("http://jenkins.mws.com:8080");

        WebDriverWait waitPage = new WebDriverWait(driver, 20);
        WebElement until = waitPage.until(ExpectedConditions.presenceOfElementLocated(By.id("ready")));

        if (until.isDisplayed()){
            System.out.println("button is displayed");
        }
    }

但我得到Timed out after 20 seconds waiting for presence of element located by: By.tagName: button

以下是我要测试的代码:

http://pastebin.com/up29pSRQ

我能找到标签按钮吗?

1 个答案:

答案 0 :(得分:4)

<button>位于iFrame内。首先切换到iFrame driver.switchTo().frame("iwg-game-full");,然后尝试。