使用for循环它首次选择对象但是在sumbit..it之后没有选择对象,因为提交后对象的id变化并显示错误信息..
代码段
for(int i=4; i<10; i++)
{
driver.findElement(By.xpath("html/body/div[1]/aside[1]/section/ul[2]/li[5]/a/i[2]")).click();
driver.findElement(By.xpath("html/body/div[1]/aside[1]/section/ul[2]/li[5]/ul/li[1]/a[1]/span")).click();
driver.findElement(By.cssSelector(".mr5.btn.btn-primary.btn-sm.pull-right.ng-scope")).click();
driver.findElement(By.xpath(".//*[@id='0' and @placeholder='Enter name']")).sendKeys("test"+i);
driver.findElement(By.xpath(".//*[@id='0' and @placeholder='Enter partnumber']")).sendKeys("test"+i);
driver.findElement(By.xpath(".//*[@id='product-description']")).sendKeys("test"+i);
driver.findElement(By.xpath(".//*[@id='select2-chosen-4' and @class='select2-chosen']")).click();
Select Group =new Select(driver.findElement(By.xpath(".//*[@ng-model='product.CategoryID']")));
Group.selectByIndex(2);
下面的ID每次都在不断变化
driver.findElement(By.xpath(".//*[@id='select2-chosen-4' and @class='select2-chosen']")).click();
我无法找到此元素独有的任何内容。
答案 0 :(得分:0)
根据html,尝试使用className找到WebElement。
driver.findElement(By.className("select2-chosen")).click();