简体   繁体   English

硒webdriver-填写表格

[英]selenium webdriver - fill up a table

I have a table (7 columns x 6 lines), where 7th column is total of cells 1-6 in each line. 我有一张表(7列x 6行),其中第7列是每行中1-6个单元格的总数。

I have to fill up whole table, I simply use sequence: driver.findElement..., element.click();element.sendKeys("strictly numeric value"); 我必须填满整个表,我只需要使用以下顺序:driver.findElement ...,element.click(); element.sendKeys(“严格数值”);

The problem is, sometimes (cca 1/3 runs) the cells in column Total are not correct calculated (or event not at all). 问题是,有时(cca 1/3运行)“总计”列中的单元格计算不正确(或完全没有事件)。 When filling up the table manualy, all totals are correct . 手动填写表格时,所有总计都是正确的 The total is calculated after some value is entered in cells 1 to 6 and any click is made. 在单元格1到6中输入一些值并单击任何值后,将计算总计。 I added a extra click after entering sixth value in each line, but without success. 在每行中输入第六个值后,我添加了额外的点击,但没有成功。

I also tried explicit wait to expected condition on the total cells, errs persists after timeout. 我还尝试了对所有单元格进行显式等待以达到预期的状态,超时后错误仍然存​​在。 Even Thread.sleep(1000); 甚至Thread.sleep(1000); after entering sixth value in line did not solve the problem. 在行中输入第六个值后没有解决问题。 Any idea, how to fill up the table and get correct totals? 任何想法,如何填写表格并获得正确的总数? thanks 谢谢

I was little bit desperate and started from beginning. 我有点绝望,从头开始。 Than figured out I don't need to click to the cell to fill it up (didn't work before some changes was made in the html source code). 比弄清楚,我不需要单击该单元格来填充它(在html源代码中进行了一些更改之前它是行不通的)。 So I reduced my code to this: 所以我将代码简化为:

WebElement L3_C1 = driver.findElement(By.xpath("//input[contains(@class,'cell A1_Number_Of_Foos')]"));
L3_C1.sendKeys("3,00");
WebElement L3_C2 = driver.findElement(By.xpath("//input[contains(@class,'cell A2_Number_Of_Foos')]"));
L3_C2.sendKeys("3,00");
WebElement L3_C3 = ... etc.

Next I construct filling up all the cells: 接下来,我构造填充所有单元格:

String[] rowId_DaP = {A BUNCH OF XPATHS};
private WebElement FE_DaP(String rowId_DaP) {return driver.findElement(By.xpath("//input[contains(@class,'rowId_DaP')]"));}
for (String rowId_DaP: rowId_DaP) {WebElement cell = FE_DaP(rowId_DaP);cell.sendKeys("3,00");

All totals are correct in 100% runs and the tests are even faster. 所有总计在100%运行中都是正确的,并且测试甚至更快。

A simple conclusion: DO NOT perform any action unless it is realy necessary. 一个简单的结论:除非确实必要,否则请不要执行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM