Trying to add data to boxes without the xpath, a tricky situation [SELENIUM & JAVA]

Viewed 41

I am working on this grid, using SELENIUM & JAVA and chromedriver.

Take a look at this and it's behaviour (it is a .gif):

gif1

When i need to add a new row to that grid i have to click on "ADD OPTION" and then a new row is inserted

The problem is that i do not understand how to pass a collection of values, i want to achieve this:

I want to pass a collection and my program should place them in the grid (2 values each row) without getting the xpath of every single box. I need to make it more efficient.


Example: i have this collection:

["fdfdfddf","989"; "RERE","6655"; "HEHE","554"; "TTER","89"]

I want my program to place them in the GRID.

Desired result: enter image description here


The problem is that in my code i do need to know the xpath of each "box" of the grid in order to insert data.

This is my code to add data to the grid:

driver.findElement(By.id("add_new_option_button")).click(); //it clicks on "Add Option" button
driver.findElement(By.xpath("//*[@id=\"manage-options-panel\"]/table/tbody/tr[40]/td[3]/input")).sendKeys("fdfdfddf");
driver.findElement(By.xpath("//*[@id=\"manage-options-panel\"]/table/tbody/tr[40]/td[5]/input")).sendKeys("989");
driver.findElement(By.id("add_new_option_button")).click();

How can i fill in the boxes without knowing the xpath of every box?

I don't want to click on every box of each row to get the xpath, i need to find another fast solution.

This is how i get the xpath of every box:

enter image description here

1 Answers

You can solve this by using xpath like.

Xpath=//*[@type='text']//following::input

Here First target a element which is just before your input box then when you add any new box then the xpath will like

Xpath=//*[@type='text']//following::input[1]
Xpath=//*[@type='text']//following::input[2]
Xpath=//*[@type='text']//following::input[3]

Now you can run a loop or otherway and input value inside the box without taking different xpath

Related