我能够使用 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:无法定位框架:iframe100-100
有什么建议么 ?