<table id="ext-comp-1389" class="x-btn x-btn-text-icon " cellspacing="0" style="width: auto;">
<tbody class="x-btn-small x-btn-icon-small-left">
<tr>
<tr>
<td class="x-btn-ml">
<td class="x-btn-mc">
<em class="x-btn-split" unselectable="on">
<button id="ext-gen128" class="x-btn-text create" type="button">New</button>
</em>
</td>
<td class="x-btn-mr">
<i> </i>
</td>
</tr>
<tr>
</tbody>
</table>
以上是嵌入 HTML 元素的方式..!HTML 元素是一个“新建”按钮,旁边有一个“+”号……如果我只单击“+”,我可以获得菜单选项,例如“D”、“P” '、'T' 和 'U'。如果我单击“新建”按钮(在代码中,就是这部分, 新建 ,没有任何内容显示为单击操作,发生在中心...下面是按钮的图像...
这是我尝试过的代码......在过去的几个小时里,
package com.hr.testpack;
import static org.junit.Assert.fail;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import com.thoughtworks.selenium.*;
public class Classtest2 {
static Selenium selenium;
static final String HOST = "localhost";
static final int PORT = 4444;
static final String BROWSER = "*firefox";
static final String URL = "http://test.test.com";
private static int buttonwidth=42;//value got from firebug computation tab...
private static final int Xoffset = (buttonwidth/2)+6;
private static final int Yoffset = 0;
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
//private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://test.test.com/RMprojectProject";
driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
}
@Test
public void testrr1() throws Exception
{
/* Only Driver...Driver's way to open a URL*/
driver.get(baseUrl + "/");
/* Webdriver Backed Selenium method-
//*selenium = new WebDriverBackedSelenium(driver, baseUrl);
//*selenium.open("/");
//selenium.wait(15000); - Never use Wait, when Implicit wait is used
//WebDriver driver = ((WebDriverBackedSelenium) selenium).getWrappedDriver();
//Driver should be instantiated for using Driver's methods for
// SeleniumBackedWebdriver
// Comments over
*/
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys("test@test.com");
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys("test124");
/* For normal Selenium RC and SeleniumBackedWebDriver method
selenium.type("username", "test");
selenium.type("password","test124");
*/
/* Internal Wait methods, which can be used for normal web
*
* applications. Methods written in the end of the program
*
* waitFor("xpath=.//*[@id='loginButton']/tbody/tr[2]/td[2]'");
waitSecond(20); */
driver.findElement(By.xpath(".//*[@id='loginButton']/tbody/tr[2]/td[2]")).click();
//selenium.waitForPageToLoad("85000");
//selenium.waitForCondition("selenium.isElementPresent(\"xpath=.//*[@id='ext-gen165']/div/table/thead/tr/td[3]\")", "70000");
WebElement ele = driver.findElement(By.xpath("//*[@id='ext-gen128']"));
Actions build = new Actions(driver);
build.moveToElement(ele, Xoffset, Yoffset).click().build().perform();
// selenium.waitForCondition("selenium.isElementPresent(\"xpath=//*[@id='ext-gen246']\")", "20000");
driver.findElement(By.xpath("//*[@id='ext-gen245']")).click();
}
@After
public void tearDown() throws Exception{
selenium.stop();
//driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
/* The Below methods can be used, for page loading/waits in
*
* normal web applications...waitFor(seconds),when called in
*
* the application, the wait happens...useful in occasions
public void waitFor(String locator) throws Exception {
for (int second = 0;; second++) {
if (second >= 60)
fail("timeout");
try {
if (selenium.isVisible(locator))
break;
} catch (Exception e) {
}
Thread.sleep(1000);
}
}
public void waitSecond(int n) throws Exception {
for (int second = 0;; second++) {
if (second >= 60)
fail("timeout");
try {
if (second > n - 1)
break;
} catch (Exception e) {
}
Thread.sleep(1000);
}
}
*/
代码已成功执行并且测试用例通过,但是当单击“+”按钮时应该看到的元素没有看到!