我的测试环境是:ubuntu 12.04,firefox 31.0,selenium 2.42.2
我的测试用例是:打开网页,单击按钮打开弹出窗口,双击此弹出窗口的一行。
在双击此弹出窗口的一行&#39>中发生了错误。 :
org.openqa.selenium.interactions.MoveTargetOutOfBoundsException : Offset within element cannot be scrolled into view: (0, 0): [object XrayWrapper [object HTMLTableRowElement]] Command duration or timeout: 29 milliseconds Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03' Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=31.0, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}] Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, webdriver.remote.sessionid=ae674cc9-7944-4e86-a893-7792cdd121ce, version=31.0, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]
我的代码是:
@Parameters({"browser","os","dataKey","username","workstation","browserVersion"})
@Test
public void intSelenium(String browser, String os, String dataKey, String username, String workstation, @Optional String browserVersion)
throws MalformedURLException, InterruptedException {
DesiredCapabilities capability = new DesiredCapabilities();
capability.setBrowserName(browser);
if(os.equals("LINUX")) {
capability.setPlatform(Platform.LINUX);
} else if(os.equals("WINDOWS")) {
capability.setPlatform(Platform.WINDOWS);
}
if(browserVersion != null) {
capability.setVersion(browserVersion);
}
testCasesData=map2.get(dataKey);
try {
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
action = new Actions(driver);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
@Parameters({"dataKey"})
@Test(alwaysRun=true,dependsOnMethods="intSelenium")
public void Login (String dataKey){
String value=null;
String attName = null;
driver.get("http://192.168.18.141:8080"+getValue("Login", "appUrl", true, dataKey));
logger.info("Completed Login");
}
@Parameters({"dataKey"})
@Test(alwaysRun=true,dependsOnMethods="Login")
public void RegressionTest312 (String dataKey){
String value=null;
String attName = null;
//double click to open specific page on right panel
by = By.xpath("//div[@id='newBookingTreeBranch']//span[text()='Default Template']");
element = driver.findElement(by);
element.sendKeys("");
action.doubleClick(element).perform();
// click twice to make the page editable, that is user/selenium can input values
by = By.xpath("//div[@id='DefBookingBasicTO']/div[3]/table/tbody/tr[not(contains(@style,'none') or contains(@class,'hide'))][1]");
action.click(driver.findElement(by)).perform();
by = By.xpath("//div[@id='DefBookingBasicTO']/div[3]/table/tbody/tr[not(contains(@style,'none') or contains(@class,'hide'))][1]");
action.click(driver.findElement(by)).perform();
//click the input box, then input value in it
by = By.xpath("//div[@id='DefBookingBasicTO']/div[3]/table/tbody//tr[not(contains(@style,'none') or contains(@class,'hide'))][1]//td[@fieldname='finalDest']//input[@type='text']");
action.click(driver.findElement(by)).perform();
by = By.xpath("//div[@id='DefBookingBasicTO']/div[3]/table/tbody//tr[not(contains(@style,'none') or contains(@class,'hide'))][1]//td[@fieldname='finalDest']//input[@type='text']");
driver.findElement(by).sendKeys(getValue("RegressionTest312", "DefBookingInfo_FinalDest_input", true, dataKey));
by = By.xpath("//div[@id='DefBookingBasicTO']/div[3]/table/tbody//tr[not(contains(@style,'none') or contains(@class,'hide'))][1]//td[@fieldname='finalDest']//input[@type='text']");
driver.findElement(by).sendKeys(getValue("RegressionTest312", "DefBookingInfo_FinalDest_input", true, dataKey));
//click the button to open popup window, this popup window shows the search result according to the value input above
by = By.xpath("//div[@id='DefBookingBasicTO']/div[3]/table/tbody//tr[not(contains(@style,'none') or contains(@class,'hide'))][1]//td[@fieldname='finalDest']//input[@type='button']");
action.click(driver.findElement(by)).perform();
// select one row in popup window, and then double click to select this row data
by = By.xpath("//div[@id='LookupResultListTO']/div[3]/table/tbody/tr[not(contains(@style,'none') or contains(@class,'hide'))][1]");
action.click(driver.findElement(by)).perform();
by = By.xpath("//div[@id='LookupResultListTO']/div[3]/table/tbody/tr[not(contains(@style,'none') or contains(@class,'hide'))][1]");
element = driver.findElement(by);
element.sendKeys("");
action.doubleClick(element).perform();
}
如何解决这个问题?
提前感谢!
答案 0 :(得分:0)
单击此按钮,当我将步骤更改为以下时,此错误消失:
element = driver.findElement(by);
element.sendKeys("");
element.click();
另外,不要忘记:
capability.setJavascriptEnabled(true)