我能够使用selenium java程序找到一个框架。以下代码成功运行:
public static void TestCase() throws IOException, InterruptedException{
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("website");
driver.findElement(By.xpath("//*[@id='username']")).sendKeys(userName);
driver.findElement(By.xpath("//*[@id='password']")).sendKeys("password");
driver.findElement(By.xpath("//*[@id='session_link']")).click();
driver.findElement(By.xpath("//*[@id='app_236']/a")).click(); //Click a link on the page
driver.switchTo().frame("iframe100-100"); //Switch to a frame within the new page
driver.findElement(By.xpath("//*[@id='yui-gen0']/li[2]/div")).click(); //Click element within the frame
}
但是如果我使用Cucumber Junit maven项目运行相同的代码,程序将无法找到该框架。
@Given("^I log into website$")
public void log_in()
{
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("website");
driver.findElement(By.xpath("//*[@id='username']")).sendKeys(userName);
driver.findElement(By.xpath("//*[@id='password']")).sendKeys("password");
driver.findElement(By.xpath("//*[@id='session_link']")).click();
}
@When("^I select the link from homepage$")
public void select_link() throws InterruptedException
{
driver.findElement(By.xpath("//*[@id='app_236']/a")).click();
}
@Then("^I should see something$")
public void click_element_within_frame()
{
driver.switchTo().frame("iframe100-100"); //Switch to a frame within the new page
driver.findElement(By.xpath("//*[@id='yui-gen0']/li[2]/div")).click(); //Click element within the frame
}
错误讯息:
31morg.openqa.selenium.NoSuchFrameException:无法找到frame:iframe100-100
有什么建议吗?