简体   繁体   English

试图在没有 xpath 的情况下向框添加数据,这是一个棘手的情况 [SELENIUM & JAVA]

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

I am working on this grid, using SELENIUM & JAVA and chromedriver.我正在处理这个网格,使用 SELENIUM & JAVA 和 chromedriver。

Take a look at this and it's behaviour (it is a.gif):看看这个及其行为(它是 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.我想传递一个集合,我的程序应该将它们放在网格中(每行 2 个值),而不需要获取每个盒子的 xpath。 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.我希望我的程序将它们放在 GRID 中。

Desired result:期望的结果: 在此处输入图像描述


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.问题是,在我的代码中,我确实需要知道网格的每个“框”的 xpath 才能插入数据。

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?我如何在不知道每个盒子的 xpath 的情况下填写盒子?

I don't want to click on every box of each row to get the xpath, i need to find another fast solution.我不想单击每一行的每个框来获取 xpath,我需要找到另一个快速解决方案。

This is how i get the xpath of every box:这就是我如何获得每个盒子的 xpath:

在此处输入图像描述

You can solve this by using xpath like.您可以通过使用 xpath 来解决这个问题。

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 会喜欢

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现在您可以运行循环或其他方式并在框内输入值而无需使用不同的 xpath

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

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