1

As per the requirement,

A dynamic web table needs to be filled from Excel sheet using selenium.

The web table is dynamic. And for each row in the excel sheet a new row has to be added in the web table

ID of a web element looks like this: asr_100_ct100_ikview_ct155_view

The next element's​ I'd looks like

asr_100_ct100_ikview_ct156_view

So, here I have done string concatenation like

Int j=155;

Driver.find element (by.id("asr_100_ct100_ikview_ct" +j+ "_view";

J++.

The above code is in for loop.

For each row in the excel sheet, a new webelement has to be found and data should be sent.

Error: unable to find the element with Id ==asr_100_ct100_ikview_ct155_view

6
  • Please be specific. I am not clear with your Question. Commented May 13, 2017 at 5:49
  • The problem here is string concatenation is not working fine. Not sure why. Commented May 13, 2017 at 6:38
  • Can you provide us with the HTML part? Commented May 13, 2017 at 15:07
  • @Sai Incase your Question is still unanswered can you please provide more info as: 1. What do you mean by For each row in the excel sheet? 2. What is the role of excel sheet data in this? 3. Can you share the relevant HTML DOM please? Commented May 15, 2017 at 13:25
  • @ dev, the steps needs to be executed are 1. Open a webpage, 2. There would be no table in the webpage Initially 3. There is a plus + sign on the webpage, upon clicking on + a new row will be added 4. The content to be filled into the webpage is available in Excel sheet. 5. For each row in Excel sheet, the + should be clicked. Commented May 16, 2017 at 14:36

3 Answers 3

1

As this below code is working for me when i am concating the integer with string.

public class Demo {
public static void main(String[] args) {
int i = 100;
String s = "Hello, I am";
for(i=100;i<105;i++){
    System.out.println(s+ i +"Test");
}
}
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply, could you please confirm if this is what you said: string s= integer.tostring(j). Driver.findelement(by.id("asr_100_ct100_ikview_ct" +j+ "_view". I am just wondering if the string concatenation what I am doing is correct syntax. Can you please suggest
No, I am not clear with your program. But As per the understanding of mine, I am giving you one example. public class Demo { public static void main(String[] args) { int i = 100; String s = "Hello, I am"; for(i=100;i<105;i++){ System.out.println(s+ i +"Test"); } } }
1

Use xpath for find element.

//*[starts-with('id', 'asr_100_ct100_ikview_ct15')]

1 Comment

We must try to add a few words about your Solution along with the code while answering to the OP. Thanks
0

try xpath instead of id!

WebDriver driver= new ChromeDriver();
driver.findElement(By.xpath("\\*[starts-with(@id,'asr_100')] 
FileInputStream fis= new FileInputStream("path");
XSSFWorkbook b= new XSSFWorkbook(fis); //make sure that it is .xlsx file
XSSFSheet sheet= b.getSheet("sheet name");
WebElement elem= driver.findElement(By.id("id of the whole table"));
List<WebElement> list= elem.findElements(By.xpath(//*[starts-with(@id,'tr id'));

int rows= sheet.getLastRowNum();
for(int i=0; i<rows;i++) {
    Row row= sheet.getRow(i);
    for(int j=0;j<row.getLastCellNum();j++) {
        for(WebElement e: list) 
                List<WebElement> tr= e.findElements(By.xpath(//*[starts-
                                   with(@id,'td id'))
                    for(WebElement d: tr)
                     d.sendKeys("data");
    }
}

if the element is a table, you have many rows and columns, you need to get data from every cell! first of all, you need to get that file from which you are reading!

//i'm sorry if I'm wrong //please correct me if i'm wrong, i'm beginner in coding!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.