为此,我需要在Web表中获取选择标签和输入标签,我创建了以下代码以在Web表中获取标签名称。
为此
// web Table
WebElement table =d.findElement(By.xpath("//*[@id='ui-grid']/div/div/div/div[2]/table/tbody"));
List<WebElement> trcount = table.findElements(By.tagName("tr"));
int size = trcount.size();
System.out.println(size);
//Using size created the for loop to find each row available in table.
for(int i=1;i<size;i++) {
//Declare the Xpath to find the particular row
By tag = By.xpath("(//*[@id='ui-grid']/div/div/div/div[2]/table/tbody/tr/td/span/select)["+i+"]");
By Input_tag = By.xpath("(//*[@id='ui-grid']/div/div/div/div[2]/table/tbody/tr/td/span/input)["+i+"]");
List<WebElement> tdcount = trcount.get(i).findElements(tag);
String tag1 = tdcount.get(i).getTagName();
System.out.println(tag1);
if(tag1.equals("select")){
d.findElement(By.xpath(tag))Select level = new Select(d.FindElement(tag));
level.selectByVisibleText("YES");
}else {
d.findElement(Input_tag).sendKeys("12");
}
}
预期结果: 如果Web表存在选择标签,则从下拉列表中选择值,否则应传递输入标签存在值。
实际结果: java.lang.IndexOutOfBoundsException:索引:1,大小:1
答案 0 :(得分:0)
<parent>....</parent>
<dependencies>
<dependency>
<groupId>group.com</groupId>
<artifactId>deps</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>java11</id>
<activation>
<jdk>11</jdk>
</activation>
<build><plugins>... some plugins specific for java 11</plugins></build>
</profile>
<profile>
<id>java7</id>
<activation>
<jdk>1.7</jdk>
</activation>
<build><plugins>... some plugins specific for java 7</plugins></build>
</profile>
</profiles>