我需要使用selnium java向具有+图标的表中添加新行

时间:2019-04-16 12:56:14

标签: java selenium-webdriver

我有一个资格表,如果是第一次输入的话,因为它是必填字段,所以不能删除。我想添加更多行以添加我的全部资格详细信息。我enter image description here已附加图像请帮助我是自动化领域的新手。

我确实想删除现有的行并使用for循环添加一行,但是它并没有添加任何新行,也没有给出任何错误。

for(int i =0; i < driver.findElements(By.xpath("//*[@class='icon-x-circle']")).size(); i++){
    driver.findElement(By.xpath("//*[@class='icon-x-circle']")).click();
}
driver.findElement(By.className("icon-plus")).click();
driver.findElement(By.xpath("//option[@value='number:127'][contains(text(),'Graduate')]")).click();
driver.findElement(By.xpath("//*[@id=\"yearpassing0\"]")).clear();
driver.findElement(By.xpath("//*[@id=\"yearpassing0\"]")).sendKeys("02-2018");
System.out.println("date");
driver.findElement(By.xpath("//*[@id=\"educational\"]/div/form/div/div[1]/table/tbody/tr/td[3]/div/input")).clear();
driver.findElement(By.xpath("//*[@id=\"educational\"]/div/form/div/div[1]/table/tbody/tr/td[3]/div/input")).sendKeys("Mumbai");
driver.findElement(By.xpath("//*[@id=\"educational\"]/div/form/div/div[1]/table/tbody/tr/td[4]/div/input")).sendKeys("60%");
time.delay(7);
WebElement uploadElement = driver.findElement(By.xpath("//*[@id=\"file0\"]"));
time.delay(5);
uploadElement.sendKeys("D:\\Preerti\\Workspace\\data.xlsx");

 System.out.println("upload");

driver.findElement(By.xpath("//*[@id=\"educational\"]//button[contains(text(), 'Save')]")).click();

这是HTML代码

<form ng-submit="addEducationDetails(userEducation);setApplyClass(3)" class="ng-pristine ng-valid">
              <div class="inner-details"> 
                <div class="table-responsive">
                  <table class="table table-bordered">
                    <thead>
                      <tr>
                        <th>Qualification*</th>
                        <!-- <th>Qualification Description</th> -->
                        <th>Passing Year*</th>
                        <th>Board/University</th>
                        <th>Grade/Score/Percentage</th>
                        <th>Attach Certificate</th>
                      <th></th>
                      </tr>
                    </thead>

                  <!--   <div class="form-group">
                          <label>Education</label>
                          <select class="form-control flat-control-inner" ng-model="list.typekey"  >
                            <option value = ""> --Please Select-- </option>
                             <option data-ng-repeat="q in qualificationsList" value="{{q.levelId}}" ng-selected="q.levelId==list.typekey">{{q.qualificationName}}</option>
                          </select>
                        </div> -->

                    <tbody>
                      <!-- ngRepeat: list in userEducation -->
                    </tbody>
                  </table>
                  <div class="text-right adder">
                  <button class="btn btn-default btn-round-add" ng-click="addnewForEducation()"><i class="icon-plus"></i></button>
                </div>
                </div>
              <div class="btn-cntnr">
              <button class="btn btn-default btn-bluer" id="" type="submit">Save</button>
              <a ng-click="cancel()">Cancel</a>
            </div>
              </div>
              </form>       

我将能够添加所有资格详细信息。它没有显示任何错误。

1 个答案:

答案 0 :(得分:0)

根据您提供的HTML,您可以使用以下代码单击+按钮:

driver.findElement(By.xpath("//button[contains(@class, 'btn-round-add')]")).click();