在treeGrid中点击某单元格中的DDL,元素能找到,但是点击事件失败。
尝试过多种方法均失败:
1) theDDL.click();
2) SeleniumUtil.jsClick(driver, theDDL);
3) Actions action = new Actions(driver);
action.moveToElement(theDDL).perform();
4) JavascriptExecutor js = (JavascriptExecutor)driver;
String jsStr = "$('td>div>div:eq("+theDDL+")').click()";
js.executeScript(jsStr);
5) JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", theDDL);
或许与第三方控件的实现方式有关,最终解决方案是:移到表格该行的前部分,然后再找到单元格中的DDL,再用click()就能成功了。
WebElement theRow = this.findBlankBenchmarkRow();
Assert.assertNotSame(theRow, null, "Should find out a blank benchmark row.");
Actions action = new Actions(driver);
System.out.println("Row size : "+theRow.getSize());
System.out.println(("X offset : "+(theRow.getSize().width)/100));
System.out.println(("Y offset : "+(theRow.getSize().height)/2));
int locx=0;
int locy=0;
locx=(theRow.getSize().width)/100;
locy=(theRow.getSize().height)/2;
action.moveToElement(theRow, locx, locy).perform();
SeleniumUtil.sleep(2);
WebElement theDDL = theRow.findElement(By.cssSelector("td div.dash-bmk-ddl"));
return theDDL;
在表格的行上,有style属性描述了超出宽度部分隐藏,或许是这个原因,导致了必须先移到该元素区域,才能点中该元素?