IE浏览器不支持Action类。是否可以使用任何其他方式多选表格中的项目?如有,请分享。
请找到表格的示例结构以选择值。现在我要选择Text1,Text3& Text5值。能够使用selenium 2.52.0在Chrome浏览器,FF浏览器中选择使用Action类,但无法在IE / Safari中选择。
<table>
<tr><td><div><span>Text1<span/><div/><td/><tr/>
<tr><td><div><span>Text2<span/><div/><td/><tr/>
<tr><td><div><span>Text3<span/><div/><td/><tr/>
<tr><td><div><span>Text4<span/><div/><td/><tr/>
<tr><td><div><span>Text5<span/><div/><td/><tr/>
<table>
用于点击的功能:
String[] items = itemName.split("\n");// Items to be clicked
Actions builder = new Actions(driver);
for(int counter = 0; counter < items.length; counter++)
{
this.listingRows = this.listing.findElement(By.cssSelector("table[id='mainTable']"));
List<WebElement> element = listingRows.findElements(By.cssSelector("tr[class='sample']>td>div>span")); //Getting the row elements
int itemCnt = element.size();
String item;
for(int i =0;i<itemCnt;i++){
item = element.get(i).getText();
if(item.equalsIgnoreCase(items[counter])){
builder.keyDown(Keys.CONTROL).click(element.get(i)).keyUp(Keys.CONTROL);
builder.build().perform();
}
}
}
答案 0 :(得分:-1)
首先,您可以检查表
WebElement data1=d.findElement(By.xpath(""));
然后,逐行选择
List<WebElement> tableRows = data1.findElements(By.tagName("tr"));
使用循环,您可以重复列
for (int i=0; i<rowSize; i++)
{
WebElement webRow = tableRows.get(i);
//Get all cell values in each row
List<WebElement> allCells = webRow.findElements(By.tagName("td"));
//System.out.println(allCells.size());
if(allCells.size() > 1)
{
row = st1.createRow(i);
for (int j=0; j<allCells.size(); j++)
{
WebElement webCell = allCells.get(j);
String text = webCell.getText();
if(text.length()>3)
{
cell = row.createCell(j);
cell.setCellValue(webCell.getText());
}
}
}
尝试一次.. !!